feat(web): terminal link context menu actions #7280
Closedflamboh(GitHub profile, opens in a new tab)wants to merge 10 commits into
main fromrefs/pull/7280/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/web/src/terminal/ghostty/surface.ts line 429OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -414,3 +412,18 @@414- linkModifierActive: boolean,415-): boolean {416- return !mouseTracking || linkModifierActive;412+export function shouldShowTerminalLinkHover(linkModifierActive: boolean): boolean {413+ return linkModifierActive;414+}415+416+export async function runTerminalLinkContextMenu({417+ link,418+ setContextMenuLink,419+ showContextMenu,420+}: {421+ readonly link: TerminalLinkWithRange | null;422+ readonly setContextMenuLink: (link: TerminalLinkWithRange | null) => void;423+ readonly showContextMenu: (linkText: string | null) => void | Promise<void>;424+}): Promise<void> {425+ setContextMenuLink(link);426+ try {427+ await showContextMenu(link?.text ?? null);428+ } finally {429+ setContextMenuLink(null);
- apps/web/src/components/ChatView.tsx line 2837OutdatedResolvedby flamboh(GitHub profile, opens in a new tab)@@ -2819,3 +2832,6 @@28192832 },28202833 [composerRef],28212834 );2835+ const addTerminalLinkToDraft = useCallback(2836+ (link: string) => {2837+ const text = terminalLinkChatText(link);apps/web/src/terminal/ghostty/surface.ts line 1332OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1301,13 +1316,17 @@1301- this.setHoveredLink(null);1302- this.canvas.style.cursor = cursor;1316+ this.setHoveredLink(this.contextMenuLink);1317+ if (this.contextMenuLink === null) this.canvas.style.cursor = cursor;13031318 }1304131913051320 private refreshHoveredLink(): void {13061321 const pointer = this.hoverPointer;13071322 const link =1308- pointer && shouldShowTerminalLinkHover(this.core.isMouseTracking(), this.linkModifierActive)1323+ this.contextMenuLink ??1324+ (pointer && shouldShowTerminalLinkHover(this.linkModifierActive)13091325 ? this.linkAt(pointer.x, pointer.y)1310- : null;1326+ : null);13111327 this.setHoveredLink(link);13121328 }131313291330+ private setContextMenuLink(link: TerminalLinkWithRange | null): void {1331+ if (this.disposed) return;1332+ this.contextMenuLink = link;
- apps/web/src/components/ChatView.tsx lines 2838 to 2844OutdatedResolvedby flamboh(GitHub profile, opens in a new tab)@@ -2819,3 +2832,13 @@28192832 },28202833 [composerRef],28212834 );2835+ const addTerminalLinkToDraft = useCallback(2836+ (link: string) => {2837+ const text = terminalLinkChatText(link);2838+ if (2839+ composerRef.current?.insertTextAtEnd(`${text} `, {2840+ ensureLeadingBoundary: true,2841+ })2842+ ) {2843+ scheduleComposerFocus();2844+ }
- apps/web/src/components/ThreadTerminalDrawer.tsx lines 268 to 269OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -256,4 +257,13 @@256257 };257258 }258259259-export type TerminalContextMenuAction = "add-to-chat" | "copy" | "paste";260+export type TerminalContextMenuAction =261+ | "add-to-chat"262+ | "add-link-to-chat"263+ | "copy"264+ | "copy-link"265+ | "open-link"266+ | "paste";267+268+export function terminalLinkChatText(link: string, cwd: string): string {269+ return isTerminalUrl(link) ? link : serializeComposerFileLink(resolvePathLinkTarget(link, cwd));
- apps/web/src/components/ThreadTerminalDrawer.tsx lines 279 to 286Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -256,4 +257,14 @@256257 };257258 }258259259-export type TerminalContextMenuAction = "add-to-chat" | "copy" | "paste";260+export type TerminalContextMenuAction =261+ | "add-to-chat"262+ | "add-link-to-chat"263+ | "copy"264+ | "copy-link"265+ | "open-link"266+ | "paste";267+268+export function terminalLinkChatText(link: string, cwd: string): string {269+ return isTerminalUrl(link) ? link : serializeComposerFileLink(resolvePathLinkTarget(link, cwd));270+}
flamboh(GitHub profile, opens in a new tab) changed the title
- apps/web/src/components/ThreadTerminalDrawer.tsx line 311Resolvedby flamboh(GitHub profile, opens in a new tab)@@ -268,11 +292,6 @@268292 ];269293 }270294271-/**272- * Right-click menu for the terminal canvas: the selection actions (disabled273- * until a selection exists) plus Paste. Paste is always offered: the browser274- * (and Electron's default editing menu) can only paste into an editable275- * element, so a canvas terminal never gets a usable entry from them.276- */277295 export function terminalContextMenuItems(options: {278296 hasSelection: boolean;297+ link: string | null;
- apps/web/src/components/ThreadTerminalDrawer.tsx line 724OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -650,6 +711,14 @@650711 case "add-to-chat":651712 if (selectionAction) addSelectionToChat(selectionAction.selection);652713 return;714+ case "add-link-to-chat":715+ if (link) handleAddTerminalLink(link);716+ return;653717 case "copy":654718 if (selectionAction) await copySelection(selectionAction.clipboardText, requestId);655719 return;720+ case "copy-link": {721+ if (!link) return;722+ const isUrl = isTerminalUrl(link);723+ await copyTerminalText(724+ link,
github-actions[bot](GitHub profile, opens in a new tab) removed labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
- apps/web/src/components/ThreadTerminalDrawer.tsx line 285Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -250,0 +265,21 @@265+ | "add-to-chat"266+ | "add-link-to-chat"267+ | "copy"268+ | "copy-link"269+ | "open-link"270+ | "open-link-external"271+ | "open-link-in-preview"272+ | "reveal-link"273+ | "paste";274+275+export function terminalFileManagerPath(link: string, cwd: string): string {276+ return splitFilePathPosition(resolvePathLinkTarget(link, cwd)).path;277+}278+279+export function terminalLinkChatText(link: string, cwd: string): string {280+ if (isTerminalUrl(link)) return link;281+ const path = terminalFileManagerPath(link, cwd);282+ const trimmedPath = path.replace(/(?!^)[/\\]+$/u, "");283+ const normalizedPath =284+ /^[A-Za-z]:$/u.test(trimmedPath) && /^[A-Za-z]:[\\/]+$/u.test(path) ? path : trimmedPath;285+ return serializeComposerFileLink(normalizedPath);
flamboh(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
0ec37e72-7d12-40c6-a216-566c52c0c6bd📥 Commits
Reviewing files that changed from the base of the PR and between f46aa75ee0bad969f60672b5e53d16a4fecd64cd and 8ba084cf1cc837e9ad2f749fb2208d5cd795e0bf.
📒 Files selected for processing (8)
apps/web/src/components/ChatView.tsxapps/web/src/components/ThreadTerminalDrawer.tsxapps/web/src/components/preview/openTerminalLinkInPreview.test.tsapps/web/src/components/preview/openTerminalLinkInPreview.tsapps/web/src/editorPreferences.tsapps/web/src/hooks/useLocalStorage.tsapps/web/src/terminal/ghostty/surface.test.tsapps/web/src/terminal/ghostty/surface.tsIncluded review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.
📝 Walkthrough
Walkthrough#
The terminal context menu now detects links and provides browser, preview, editor, reveal, copy, and chat actions. Link highlights persist while menus are open. Chat view inserts terminal links into the composer.
Changes#
Terminal link actions
apps/web/src/terminal/ghostty/surface.ts,apps/web/src/terminal/ghostty/surface.test.tsapps/web/src/components/preview/openTerminalLinkInPreview.ts,apps/web/src/components/preview/openTerminalLinkInPreview.test.ts,apps/web/src/editorPreferences.ts,apps/web/src/editorPreferences.test.ts,apps/web/src/hooks/useLocalStorage.tsapps/web/src/components/ThreadTerminalDrawer.tsx,apps/web/src/components/ThreadTerminalDrawer.test.ts,apps/web/src/pierre-icons.ts,apps/web/src/pierre-icons.test.tsapps/web/src/components/ChatView.tsxEstimated code review effort: 4 (Complex) | ~45 minutes
Sequence Diagram(s)#
Suggested reviewers:
juliusmarminge,t3dotgg,maria-rcksMerge Risk: ⚪ Minimal · up to
8ba08Terminal root paths retain a visible label when added to chat, and no current merge-blocking risk remains.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 passed)
✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands.