From 272e355ee96890f4b2bed457e796ccec7cd962e3 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 24 Jun 2026 19:35:40 -0700 Subject: [PATCH] Split open-in editor controls into panel and toolbar variants - Move Open in editor shortcut handling into a shared hook - Show Open in picker inside the thread details panel and restyle PR actions - Tighten popover positioning for the panel layout --- .../BranchToolbarBranchSelector.tsx | 47 +++++++++- apps/web/src/components/ChatView.tsx | 21 +++-- apps/web/src/components/chat/ChatHeader.tsx | 58 ++----------- .../src/components/chat/OpenInPicker.logic.ts | 13 +++ ...hatHeader.test.ts => OpenInPicker.test.ts} | 2 +- apps/web/src/components/chat/OpenInPicker.tsx | 87 +++++++++---------- .../components/chat/OpenInPickerShortcut.ts | 43 +++++++++ .../components/chat/PanelLayoutControls.tsx | 11 +-- .../components/chat/ThreadDetailsPanel.tsx | 22 ++++- .../chat/threadDetailsPanelStyles.ts | 12 +-- .../src/components/files/FilePreviewPanel.tsx | 1 - apps/web/src/components/ui/popover.tsx | 3 + 12 files changed, 198 insertions(+), 122 deletions(-) create mode 100644 apps/web/src/components/chat/OpenInPicker.logic.ts rename apps/web/src/components/chat/{ChatHeader.test.ts => OpenInPicker.test.ts} (95%) create mode 100644 apps/web/src/components/chat/OpenInPickerShortcut.ts diff --git a/apps/web/src/components/BranchToolbarBranchSelector.tsx b/apps/web/src/components/BranchToolbarBranchSelector.tsx index 4ea753eb52..f0d03b86ec 100644 --- a/apps/web/src/components/BranchToolbarBranchSelector.tsx +++ b/apps/web/src/components/BranchToolbarBranchSelector.tsx @@ -537,7 +537,7 @@ export function BranchToolbarBranchSelector({ resolvedActiveBranch, }); - // PR pill shown next to the branch selector when the active branch has one. + // Change request state is compact in the composer and gets a dedicated row in the panel. const branchPr = resolveThreadPr(resolvedActiveBranch, branchStatusQuery.data ?? null); const branchPrStatus = prStatusIndicator(branchPr, branchStatusQuery.data?.sourceControlProvider); // Action-oriented tooltip (the pill opens the PR), distinct from the sidebar's @@ -546,6 +546,12 @@ export function BranchToolbarBranchSelector({ ? `Open ${sourceControlPresentation.terminology.singular} #${branchPr.number} (${branchPr.state}) in browser` : ""; const openPrLink = useOpenPrLink(); + const panelPrStateClass = + branchPr?.state === "open" + ? "bg-emerald-500/10 text-emerald-700 dark:bg-emerald-400/10 dark:text-emerald-300" + : branchPr?.state === "merged" + ? "bg-violet-500/10 text-violet-700 dark:bg-violet-400/10 dark:text-violet-300" + : "bg-muted text-muted-foreground"; function renderPickerItem(itemValue: string, index: number) { if (checkoutPullRequestItemValue && itemValue === checkoutPullRequestItemValue) { @@ -645,12 +651,12 @@ export function BranchToolbarBranchSelector({ >
- {branchPr && branchPrStatus ? ( + {displayMode !== "panel" && branchPr && branchPrStatus ? ( + {displayMode === "panel" && branchPr && branchPrStatus ? ( + + openPrLink(event, branchPrStatus.url)} + /> + } + > + + + View {sourceControlPresentation.terminology.shortLabel} #{branchPr.number} + + + + + {branchPrStatus.tooltip} + + ) : null}
diff --git a/apps/web/src/components/chat/ChatHeader.tsx b/apps/web/src/components/chat/ChatHeader.tsx index 8486aad52a..999c0dd259 100644 --- a/apps/web/src/components/chat/ChatHeader.tsx +++ b/apps/web/src/components/chat/ChatHeader.tsx @@ -1,54 +1,24 @@ -import { - type EnvironmentId, - type EditorId, - type ResolvedKeybindingsConfig, -} from "@t3tools/contracts"; import { memo } from "react"; import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip"; import { SidebarTrigger } from "../ui/sidebar"; -import { OpenInPicker } from "./OpenInPicker"; -import { usePrimaryEnvironmentId } from "../../state/environments"; import { cn } from "~/lib/utils"; interface ChatHeaderProps { - activeThreadEnvironmentId: EnvironmentId; activeThreadTitle: string; - activeProjectName: string | undefined; - openInCwd: string | null; - keybindings: ResolvedKeybindingsConfig; - availableEditors: ReadonlyArray; rightPanelOpen: boolean; } -export function shouldShowOpenInPicker(input: { - readonly activeProjectName: string | undefined; - readonly activeThreadEnvironmentId: EnvironmentId; - readonly primaryEnvironmentId: EnvironmentId | null; -}): boolean { - return ( - Boolean(input.activeProjectName) && - input.primaryEnvironmentId !== null && - input.activeThreadEnvironmentId === input.primaryEnvironmentId - ); -} - export const ChatHeader = memo(function ChatHeader({ - activeThreadEnvironmentId, activeThreadTitle, - activeProjectName, - openInCwd, - keybindings, - availableEditors, rightPanelOpen, }: ChatHeaderProps) { - const primaryEnvironmentId = usePrimaryEnvironmentId(); - const showOpenInPicker = shouldShowOpenInPicker({ - activeProjectName, - activeThreadEnvironmentId, - primaryEnvironmentId, - }); return ( -
+
@@ -65,22 +35,6 @@ export const ChatHeader = memo(function ChatHeader({ {activeThreadTitle}
-
- {showOpenInPicker && ( - - )} -
); }); diff --git a/apps/web/src/components/chat/OpenInPicker.logic.ts b/apps/web/src/components/chat/OpenInPicker.logic.ts new file mode 100644 index 0000000000..fed3d7f75f --- /dev/null +++ b/apps/web/src/components/chat/OpenInPicker.logic.ts @@ -0,0 +1,13 @@ +import type { EnvironmentId } from "@t3tools/contracts"; + +export function shouldShowOpenInPicker(input: { + readonly activeProjectName: string | undefined; + readonly activeThreadEnvironmentId: EnvironmentId; + readonly primaryEnvironmentId: EnvironmentId | null; +}): boolean { + return ( + Boolean(input.activeProjectName) && + input.primaryEnvironmentId !== null && + input.activeThreadEnvironmentId === input.primaryEnvironmentId + ); +} diff --git a/apps/web/src/components/chat/ChatHeader.test.ts b/apps/web/src/components/chat/OpenInPicker.test.ts similarity index 95% rename from apps/web/src/components/chat/ChatHeader.test.ts rename to apps/web/src/components/chat/OpenInPicker.test.ts index d716092fc3..ab0689a6e1 100644 --- a/apps/web/src/components/chat/ChatHeader.test.ts +++ b/apps/web/src/components/chat/OpenInPicker.test.ts @@ -1,7 +1,7 @@ import { EnvironmentId } from "@t3tools/contracts"; import { describe, expect, it } from "vite-plus/test"; -import { shouldShowOpenInPicker } from "./ChatHeader"; +import { shouldShowOpenInPicker } from "./OpenInPicker.logic"; describe("shouldShowOpenInPicker", () => { const primaryEnvironmentId = EnvironmentId.make("environment-primary"); diff --git a/apps/web/src/components/chat/OpenInPicker.tsx b/apps/web/src/components/chat/OpenInPicker.tsx index 9def7a4646..46ec20d9e3 100644 --- a/apps/web/src/components/chat/OpenInPicker.tsx +++ b/apps/web/src/components/chat/OpenInPicker.tsx @@ -1,6 +1,6 @@ import { EditorId, type EnvironmentId, type ResolvedKeybindingsConfig } from "@t3tools/contracts"; -import { memo, useCallback, useEffect, useMemo } from "react"; -import { isOpenFavoriteEditorShortcut, shortcutLabelForCommand } from "../../keybindings"; +import { memo, useCallback, useMemo } from "react"; +import { shortcutLabelForCommand } from "../../keybindings"; import { usePreferredEditor } from "../../editorPreferences"; import { ChevronDownIcon, FolderClosedIcon } from "lucide-react"; import { Button } from "../ui/button"; @@ -31,9 +31,16 @@ import { RustRoverIcon, WebStormIcon, } from "../JetBrainsIcons"; -import { isMacPlatform, isWindowsPlatform } from "~/lib/utils"; +import { cn, isMacPlatform, isWindowsPlatform } from "~/lib/utils"; import { shellEnvironment } from "~/state/shell"; import { useAtomCommand } from "~/state/use-atom-command"; +import { + THREAD_DETAILS_PANEL_ICON_CLASS, + THREAD_DETAILS_PANEL_SPLIT_GROUP_CLASS, + THREAD_DETAILS_PANEL_SPLIT_PRIMARY_CLASS, + THREAD_DETAILS_PANEL_SPLIT_SECONDARY_CLASS, + THREAD_DETAILS_PANEL_SPLIT_SEPARATOR_CLASS, +} from "./threadDetailsPanelStyles"; const resolveOptions = (platform: string, availableEditors: ReadonlyArray) => { const baseOptions: ReadonlyArray<{ label: string; Icon: Icon; value: EditorId }> = [ @@ -157,15 +164,17 @@ export const OpenInPicker = memo(function OpenInPicker({ availableEditors, openInCwd, compact = false, - enableShortcut = true, + displayMode = "toolbar", }: { environmentId: EnvironmentId; keybindings: ResolvedKeybindingsConfig; availableEditors: ReadonlyArray; openInCwd: string | null; compact?: boolean; - enableShortcut?: boolean; + displayMode?: "toolbar" | "panel"; }) { + const isPanel = displayMode === "panel"; + const ActionGroup = isPanel ? "div" : Group; const openInEditorMutation = useAtomCommand(shellEnvironment.openInEditor, "open in editor"); const [preferredEditor, setPreferredEditor] = usePreferredEditor(availableEditors); const options = useMemo( @@ -196,62 +205,52 @@ export const OpenInPicker = memo(function OpenInPicker({ () => shortcutLabelForCommand(keybindings, "editor.openFavorite"), [keybindings], ); - - useEffect(() => { - if (!enableShortcut) return; - const handler = (e: globalThis.KeyboardEvent) => { - if (!isOpenFavoriteEditorShortcut(e, keybindings)) return; - if (!openInCwd) return; - if (!preferredEditor) return; - - e.preventDefault(); - void openInEditorMutation({ - environmentId, - input: { - cwd: openInCwd, - editor: preferredEditor, - }, - }); - }; - window.addEventListener("keydown", handler); - return () => window.removeEventListener("keydown", handler); - }, [ - enableShortcut, - environmentId, - keybindings, - openInCwd, - openInEditorMutation, - preferredEditor, - ]); + const primaryLabel = isPanel ? `Open in ${primaryOption?.label ?? "editor"}` : "Open"; return ( - + - + {isPanel ? ( + + ); }); diff --git a/apps/web/src/components/chat/OpenInPickerShortcut.ts b/apps/web/src/components/chat/OpenInPickerShortcut.ts new file mode 100644 index 0000000000..91102b40c5 --- /dev/null +++ b/apps/web/src/components/chat/OpenInPickerShortcut.ts @@ -0,0 +1,43 @@ +import type { EditorId, EnvironmentId, ResolvedKeybindingsConfig } from "@t3tools/contracts"; +import { useEffect } from "react"; + +import { usePreferredEditor } from "../../editorPreferences"; +import { isOpenFavoriteEditorShortcut } from "../../keybindings"; +import { shellEnvironment } from "../../state/shell"; +import { useAtomCommand } from "../../state/use-atom-command"; + +export function useOpenFavoriteEditorShortcut({ + enabled, + environmentId, + keybindings, + availableEditors, + openInCwd, +}: { + enabled: boolean; + environmentId: EnvironmentId; + keybindings: ResolvedKeybindingsConfig; + availableEditors: ReadonlyArray; + openInCwd: string | null; +}) { + const openInEditorMutation = useAtomCommand(shellEnvironment.openInEditor, "open in editor"); + const [preferredEditor] = usePreferredEditor(availableEditors); + + useEffect(() => { + if (!enabled) return; + const handler = (event: globalThis.KeyboardEvent) => { + if (!isOpenFavoriteEditorShortcut(event, keybindings)) return; + if (!openInCwd || !preferredEditor) return; + + event.preventDefault(); + void openInEditorMutation({ + environmentId, + input: { + cwd: openInCwd, + editor: preferredEditor, + }, + }); + }; + window.addEventListener("keydown", handler); + return () => window.removeEventListener("keydown", handler); + }, [enabled, environmentId, keybindings, openInCwd, openInEditorMutation, preferredEditor]); +} diff --git a/apps/web/src/components/chat/PanelLayoutControls.tsx b/apps/web/src/components/chat/PanelLayoutControls.tsx index fd3f632c73..bc0fcf9ed5 100644 --- a/apps/web/src/components/chat/PanelLayoutControls.tsx +++ b/apps/web/src/components/chat/PanelLayoutControls.tsx @@ -100,12 +100,13 @@ export const PanelLayoutControls = memo(function PanelLayoutControls({ {threadPanelPopoverContent} diff --git a/apps/web/src/components/chat/ThreadDetailsPanel.tsx b/apps/web/src/components/chat/ThreadDetailsPanel.tsx index ec4f7d2649..6398f35065 100644 --- a/apps/web/src/components/chat/ThreadDetailsPanel.tsx +++ b/apps/web/src/components/chat/ThreadDetailsPanel.tsx @@ -1,4 +1,5 @@ import type { + EditorId, EnvironmentId, ProjectScript, ResolvedKeybindingsConfig, @@ -18,6 +19,7 @@ import ProjectScriptsControl, { } from "../ProjectScriptsControl"; import { Button } from "../ui/button"; import { cn } from "../../lib/utils"; +import { OpenInPicker } from "./OpenInPicker"; import { ThreadRelationshipsPanel } from "./ThreadRelationshipsControl"; interface VersionMismatchIssue { @@ -37,6 +39,8 @@ export interface ThreadDetailsPanelProps { activeProjectScripts: ReadonlyArray | undefined; preferredScriptId: string | null; keybindings: ResolvedKeybindingsConfig; + availableEditors: ReadonlyArray; + showOpenInPicker: boolean; gitCwd: string | null; isGitRepo: boolean; envLocked: boolean; @@ -132,20 +136,20 @@ export function ThreadDetailsPanel(props: ThreadDetailsPanelProps) { const card = (
-
+

- Project / environment + Workspace

@@ -232,6 +236,16 @@ export function ThreadDetailsPanel(props: ThreadDetailsPanelProps) { + {props.showOpenInPicker ? ( + + ) : null} + {props.activeProjectScripts ? ( ) : null} {isMarkdown ? ( diff --git a/apps/web/src/components/ui/popover.tsx b/apps/web/src/components/ui/popover.tsx index dd64bb2c14..de6a94d8f4 100644 --- a/apps/web/src/components/ui/popover.tsx +++ b/apps/web/src/components/ui/popover.tsx @@ -25,6 +25,7 @@ function PopoverPopup({ align = "center", sideOffset = 4, alignOffset = 0, + collisionAvoidance, tooltipStyle = false, anchor, ...props @@ -35,6 +36,7 @@ function PopoverPopup({ align?: PopoverPrimitive.Positioner.Props["align"]; sideOffset?: PopoverPrimitive.Positioner.Props["sideOffset"]; alignOffset?: PopoverPrimitive.Positioner.Props["alignOffset"]; + collisionAvoidance?: PopoverPrimitive.Positioner.Props["collisionAvoidance"]; tooltipStyle?: boolean; anchor?: PopoverPrimitive.Positioner.Props["anchor"]; }) { @@ -44,6 +46,7 @@ function PopoverPopup({ align={align} alignOffset={alignOffset} anchor={anchor} + collisionAvoidance={collisionAvoidance} className={cn( "z-50 h-(--positioner-height) w-(--positioner-width) max-w-(--available-width) transition-[top,left,right,bottom,transform] data-instant:transition-none", positionerClassName,