diff --git a/src/renderer/src/components/terminal-pane/TerminalContextMenu.test.tsx b/src/renderer/src/components/terminal-pane/TerminalContextMenu.test.tsx index a70b378d2..0cfa3f161 100644 --- a/src/renderer/src/components/terminal-pane/TerminalContextMenu.test.tsx +++ b/src/renderer/src/components/terminal-pane/TerminalContextMenu.test.tsx @@ -57,8 +57,6 @@ function renderMenu(overrides: Record = {}): void { canClosePane: true, canExpandPane: true, menuPaneIsExpanded: false, - linkUrl: null, - onOpenLinkInDefaultBrowser: vi.fn(), onCopy: vi.fn(), onPaste: vi.fn(), onSplitRight: vi.fn(), @@ -116,24 +114,6 @@ describe('TerminalContextMenu', () => { expect(onForkAgentSession).not.toHaveBeenCalled() }) - it('shows "Open in Default Browser" only when a link is under the cursor', () => { - renderMenu({ linkUrl: null }) - expect( - items.list.some((item) => childrenText(item.children) === 'Open in Default Browser') - ).toBe(false) - - items.list = [] - const onOpenLinkInDefaultBrowser = vi.fn() - renderMenu({ linkUrl: 'https://example.com/docs', onOpenLinkInDefaultBrowser }) - - const openLinkItem = items.list.find( - (item) => childrenText(item.children) === 'Open in Default Browser' - ) - expect(openLinkItem).toBeDefined() - openLinkItem?.onSelect?.() - expect(onOpenLinkInDefaultBrowser).toHaveBeenCalledTimes(1) - }) - it('shows one shortcut per terminal menu action on Windows', () => { vi.stubGlobal('navigator', { userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)' diff --git a/src/renderer/src/components/terminal-pane/TerminalContextMenu.tsx b/src/renderer/src/components/terminal-pane/TerminalContextMenu.tsx index d46d66e58..749b1e98a 100644 --- a/src/renderer/src/components/terminal-pane/TerminalContextMenu.tsx +++ b/src/renderer/src/components/terminal-pane/TerminalContextMenu.tsx @@ -4,7 +4,6 @@ import { ClipboardCopy, Copy, Eraser, - ExternalLink, GitFork, Maximize2, MessageSquare, @@ -32,11 +31,12 @@ import { } from '@/components/ui/dropdown-menu' import { shouldIgnoreTerminalMenuPointerDownOutside } from './terminal-context-menu-dismiss' import type { TerminalQuickCommand } from '../../../../shared/types' +import { isTerminalAgentQuickCommand } from '../../../../shared/terminal-quick-commands' import { formatPrimaryShortcutLabel } from '@/hooks/useShortcutLabel' +import { AgentIcon } from '@/lib/agent-catalog' import type { KeybindingOverrides } from '../../../../shared/keybindings' import { translate } from '@/i18n/i18n' import { isMacPlatform, nativeChatToggleShortcutLabel } from '../native-chat/native-chat-shortcut' -import { TerminalQuickCommandMenuItem } from './TerminalQuickCommandMenuItem' type TerminalContextMenuProps = { open: boolean @@ -46,8 +46,6 @@ type TerminalContextMenuProps = { canClosePane: boolean canExpandPane: boolean menuPaneIsExpanded: boolean - linkUrl: string | null - onOpenLinkInDefaultBrowser: () => void onCopy: () => void onPaste: () => void onSplitRight: () => void @@ -83,8 +81,6 @@ export default function TerminalContextMenu({ canClosePane, canExpandPane, menuPaneIsExpanded, - linkUrl, - onOpenLinkInDefaultBrowser, onCopy, onPaste, onSplitRight, @@ -132,6 +128,27 @@ export default function TerminalContextMenu({ const showEqualizeShortcut = shortcuts.equalize !== 'Unassigned' const showSetTitleShortcut = shortcuts.setTitle !== 'Unassigned' const showClearPaneTitleShortcut = shortcuts.clearPaneTitle !== 'Unassigned' + const renderQuickCommandItem = (command: TerminalQuickCommand): React.JSX.Element => ( + onQuickCommand(command)}> + {isTerminalAgentQuickCommand(command) ? ( + + + + ) : ( + + )} + {command.label} + {!isTerminalAgentQuickCommand(command) && !command.appendEnter ? ( + + {translate('auto.components.terminal.pane.TerminalContextMenu.c2f0b72b8d', 'Insert')} + + ) : null} + + ) return ( - {linkUrl ? ( - <> - - - {translate( - 'auto.components.terminal.pane.TerminalContextMenu.openLinkDefaultBrowser', - 'Open in Default Browser' - )} - - - - ) : null} {translate('auto.components.terminal.pane.TerminalContextMenu.f3eeb1de13', 'Copy')} @@ -215,13 +220,7 @@ export default function TerminalContextMenu({ {quickCommandRepoLabel} - {repoQuickCommands.map((command) => ( - - ))} + {repoQuickCommands.map(renderQuickCommandItem)} ) : null} {globalQuickCommands.length > 0 ? ( @@ -235,13 +234,7 @@ export default function TerminalContextMenu({ )} ) : null} - {globalQuickCommands.map((command) => ( - - ))} + {globalQuickCommands.map(renderQuickCommandItem)} ) : null} diff --git a/src/renderer/src/components/terminal-pane/TerminalPane.tsx b/src/renderer/src/components/terminal-pane/TerminalPane.tsx index 4db3c5035..d3724351d 100644 --- a/src/renderer/src/components/terminal-pane/TerminalPane.tsx +++ b/src/renderer/src/components/terminal-pane/TerminalPane.tsx @@ -2983,8 +2983,6 @@ export default function TerminalPane({ menuPaneIsExpanded={ contextMenu.menuPaneId !== null && contextMenu.menuPaneId === expandedPaneId } - linkUrl={contextMenu.menuLinkUrl} - onOpenLinkInDefaultBrowser={contextMenu.onOpenLinkInDefaultBrowser} onCopy={() => void contextMenu.onCopy()} onPaste={() => void contextMenu.onPaste()} onSplitRight={contextMenu.onSplitRight} diff --git a/src/renderer/src/components/terminal-pane/TerminalQuickCommandMenuItem.tsx b/src/renderer/src/components/terminal-pane/TerminalQuickCommandMenuItem.tsx deleted file mode 100644 index 4dac903b0..000000000 --- a/src/renderer/src/components/terminal-pane/TerminalQuickCommandMenuItem.tsx +++ /dev/null @@ -1,38 +0,0 @@ -import { Play } from 'lucide-react' -import { DropdownMenuItem, DropdownMenuShortcut } from '@/components/ui/dropdown-menu' -import { AgentIcon } from '@/lib/agent-catalog' -import { translate } from '@/i18n/i18n' -import type { TerminalQuickCommand } from '../../../../shared/types' -import { isTerminalAgentQuickCommand } from '../../../../shared/terminal-quick-commands' - -type TerminalQuickCommandMenuItemProps = { - command: TerminalQuickCommand - onSelect: (command: TerminalQuickCommand) => void -} - -export function TerminalQuickCommandMenuItem({ - command, - onSelect -}: TerminalQuickCommandMenuItemProps): React.JSX.Element { - return ( - onSelect(command)}> - {isTerminalAgentQuickCommand(command) ? ( - - - - ) : ( - - )} - {command.label} - {!isTerminalAgentQuickCommand(command) && !command.appendEnter ? ( - - {translate('auto.components.terminal.pane.TerminalContextMenu.c2f0b72b8d', 'Insert')} - - ) : null} - - ) -} diff --git a/src/renderer/src/components/terminal-pane/terminal-url-link-hit-testing.test.ts b/src/renderer/src/components/terminal-pane/terminal-url-link-hit-testing.test.ts index 8af8a0068..87d03c748 100644 --- a/src/renderer/src/components/terminal-pane/terminal-url-link-hit-testing.test.ts +++ b/src/renderer/src/components/terminal-pane/terminal-url-link-hit-testing.test.ts @@ -1,8 +1,6 @@ import { afterEach, describe, expect, it, vi } from 'vitest' import { extractTerminalHttpLinks, - getTerminalHttpLinkAtBufferPosition, - getTerminalHttpLinkForMouseEvent, TERMINAL_HTTP_URL_MAX_LENGTH } from './terminal-url-link-hit-testing' @@ -49,127 +47,3 @@ describe('extractTerminalHttpLinks', () => { expect(matchAllSpy).not.toHaveBeenCalled() }) }) - -describe('terminal HTTP link hit testing', () => { - type TestBufferLine = { - isWrapped: boolean - length: number - translateToString: ( - trimRight?: boolean, - startColumn?: number, - endColumn?: number, - outColumns?: number[] - ) => string - } - - function defaultColumnsForText(text: string): number[] { - return Array.from({ length: text.length + 1 }, (_value, index) => index) - } - - function makeBufferLine( - text: string, - options: { isWrapped?: boolean; columns?: number[] } = {} - ): TestBufferLine { - const columns = options.columns ?? defaultColumnsForText(text) - return { - isWrapped: options.isWrapped ?? false, - length: text.length, - translateToString: ( - _trimRight?: boolean, - startColumn = 0, - endColumn = text.length, - outColumns?: number[] - ) => { - if (outColumns) { - outColumns.length = 0 - for (let index = startColumn; index <= endColumn; index++) { - outColumns.push(columns[index] ?? index) - } - } - return text.slice(startColumn, endColumn) - } - } - } - - function makeBuffer( - rows: TestBufferLine[] - ): Parameters[0] { - return { getLine: (y: number) => rows[y] } as Parameters< - typeof getTerminalHttpLinkAtBufferPosition - >[0] - } - - it('returns the URL at a buffer position without opening it', () => { - const line = 'Open https://example.com/docs?q=orca now' - - expect( - getTerminalHttpLinkAtBufferPosition( - makeBuffer([makeBufferLine(line)]), - { x: line.indexOf('example') + 1, y: 1 }, - 80 - ) - ).toBe('https://example.com/docs?q=orca') - }) - - it('returns null when the buffer position is outside the URL', () => { - const line = 'Open https://example.com/docs now' - - expect( - getTerminalHttpLinkAtBufferPosition(makeBuffer([makeBufferLine(line)]), { x: 2, y: 1 }, 80) - ).toBeNull() - }) - - // Why: the context-menu "Open in Default Browser" item hands this URL to - // shell.openExternal, so a dangerous scheme under the cursor must never be - // surfaced as an openable link. - it.each(['file:///etc/passwd', 'javascript:alert(1)', 'smb://host/share', 'vscode://x'])( - 'returns null for the non-http scheme %s', - (dangerousUrl) => { - const line = `Open ${dangerousUrl} now` - - expect( - getTerminalHttpLinkAtBufferPosition( - makeBuffer([makeBufferLine(line)]), - { x: line.indexOf(dangerousUrl) + 1, y: 1 }, - 80 - ) - ).toBeNull() - } - ) - - it('returns wrapped URLs from mouse coordinates', () => { - const rows = [ - makeBufferLine('Visit https://exa'), - makeBufferLine('mple.com/docs', { isWrapped: true }) - ] - const screen = { - getBoundingClientRect: () => ({ - left: 10, - top: 20, - width: 200, - height: 40 - }) - } - const terminal = { - cols: 20, - rows: 2, - element: { querySelector: () => screen }, - buffer: { - active: { - viewportY: 0, - getLine: (y: number) => rows[y] - } - } - } - - expect( - getTerminalHttpLinkForMouseEvent( - terminal as unknown as Parameters[0], - { - clientX: 30, - clientY: 45 - } - ) - ).toBe('https://example.com/docs') - }) -}) diff --git a/src/renderer/src/components/terminal-pane/terminal-url-link-hit-testing.ts b/src/renderer/src/components/terminal-pane/terminal-url-link-hit-testing.ts index 93ff8954b..67505d5f6 100644 --- a/src/renderer/src/components/terminal-pane/terminal-url-link-hit-testing.ts +++ b/src/renderer/src/components/terminal-pane/terminal-url-link-hit-testing.ts @@ -191,7 +191,7 @@ function getTerminalScreenElement(terminal: Terminal): HTMLElement | null { function getBufferPositionForTerminalMouseEvent( terminal: Terminal, - event: Pick + event: MouseEvent ): { x: number; y: number } | null { const screenElement = getTerminalScreenElement(terminal) if (!screenElement || terminal.cols <= 0 || terminal.rows <= 0) { @@ -260,34 +260,9 @@ export function openHttpLinkAtBufferPosition( terminalColumns: number, deps: UrlLinkHitTestDeps ): boolean { - const url = getTerminalHttpLinkAtBufferPosition(buffer, position, terminalColumns) - if (!url) { - return false - } - - openTerminalHttpLink(url, deps) - return true -} - -export function getTerminalHttpLinkForMouseEvent( - terminal: Terminal, - event: Pick -): string | null { - const position = getBufferPositionForTerminalMouseEvent(terminal, event) - if (!position) { - return null - } - return getTerminalHttpLinkAtBufferPosition(terminal.buffer.active, position, terminal.cols) -} - -export function getTerminalHttpLinkAtBufferPosition( - buffer: { getLine(y: number): IBufferLine | undefined }, - position: { x: number; y: number }, - terminalColumns: number -): string | null { const logicalLines = buildCandidateLogicalLinesForBufferPosition(buffer, position.y) if (logicalLines.length === 0) { - return null + return false } for (const logicalLine of logicalLines) { @@ -296,11 +271,12 @@ export function getTerminalHttpLinkAtBufferPosition( if (!range || !rangeContainsBufferPosition(range, position, terminalColumns)) { continue } - return parsed.url + openTerminalHttpLink(parsed.url, deps) + return true } } - return null + return false } export function openTerminalHttpLink(url: string, deps: UrlLinkHitTestDeps): void { diff --git a/src/renderer/src/components/terminal-pane/use-terminal-pane-context-menu.ts b/src/renderer/src/components/terminal-pane/use-terminal-pane-context-menu.ts index 2dd939f61..d84f1a080 100644 --- a/src/renderer/src/components/terminal-pane/use-terminal-pane-context-menu.ts +++ b/src/renderer/src/components/terminal-pane/use-terminal-pane-context-menu.ts @@ -41,8 +41,6 @@ import { useAppStore } from '@/store' import { translate } from '@/i18n/i18n' import { recordTerminalUserInputForLeaf } from './terminal-input-activity' import { copyTerminalHandleForPane } from './terminal-handle-copy' -import { getTerminalHttpLinkForMouseEvent } from './terminal-url-link-hit-testing' -import { openHttpLink } from '@/lib/http-link-routing' const CLOSE_ALL_CONTEXT_MENUS_EVENT = 'orca-close-all-context-menus' @@ -83,8 +81,6 @@ type TerminalMenuState = { menuOpenedAtRef: React.RefObject paneCount: number menuPaneId: number | null - menuLinkUrl: string | null - onOpenLinkInDefaultBrowser: () => void onContextMenuCapture: (event: React.MouseEvent) => void onPaneTitleContextMenu: (event: React.MouseEvent, paneId: number) => void onCopy: () => Promise @@ -128,7 +124,6 @@ export function useTerminalPaneContextMenu({ const menuOpenedAtRef = useRef(0) const [open, setOpen] = useState(false) const [point, setPoint] = useState({ x: 0, y: 0 }) - const [menuLinkUrl, setMenuLinkUrl] = useState(null) useEffect(() => { const closeMenu = (): void => { @@ -187,17 +182,6 @@ export function useTerminalPaneContextMenu({ pane.terminal.focus() } - const onOpenLinkInDefaultBrowser = (): void => { - if (!menuLinkUrl) { - return - } - // Why: route through the shared funnel (not shell.openUrl directly) so this - // matches shift+click's system-browser path, including the loopback - // worktree-label rewrite for local dev-server links. - openHttpLink(menuLinkUrl, { worktreeId, forceSystemBrowser: true }) - resolveMenuPane()?.terminal.focus() - } - const getShortcutPlatform = (): NodeJS.Platform => { if (navigator.userAgent.includes('Mac')) { return 'darwin' @@ -488,7 +472,6 @@ export function useTerminalPaneContextMenu({ const manager = managerRef.current if (!manager) { contextPaneIdRef.current = null - setMenuLinkUrl(null) return } const clickedPane = @@ -516,11 +499,6 @@ export function useTerminalPaneContextMenu({ return } - // Why: only hit-test the link once the menu is actually opening; the Windows - // copy/paste path above returns without a menu and needs no link lookup. - setMenuLinkUrl( - clickedPane ? getTerminalHttpLinkForMouseEvent(clickedPane.terminal, event.nativeEvent) : null - ) menuOpenedAtRef.current = Date.now() const bounds = boundsElement.getBoundingClientRect() setPoint({ x: event.clientX - bounds.left, y: event.clientY - bounds.top }) @@ -532,14 +510,12 @@ export function useTerminalPaneContextMenu({ if (!manager) { event.preventDefault() contextPaneIdRef.current = null - setMenuLinkUrl(null) return } const target = event.target if (!(target instanceof Node)) { event.preventDefault() contextPaneIdRef.current = null - setMenuLinkUrl(null) return } const clickedPane = manager.getPanes().find((pane) => pane.container.contains(target)) ?? null @@ -568,8 +544,6 @@ export function useTerminalPaneContextMenu({ menuOpenedAtRef, paneCount, menuPaneId, - menuLinkUrl, - onOpenLinkInDefaultBrowser, onContextMenuCapture, onPaneTitleContextMenu, onCopy, diff --git a/src/renderer/src/i18n/locales/en.json b/src/renderer/src/i18n/locales/en.json index ca2bbd195..6a2d2f906 100644 --- a/src/renderer/src/i18n/locales/en.json +++ b/src/renderer/src/i18n/locales/en.json @@ -2452,7 +2452,6 @@ "0a917b591a": "Paste", "f3eeb1de13": "Copy", "c2f0b72b8d": "Insert", - "openLinkDefaultBrowser": "Open in Default Browser", "925f49f210": "Expand Pane", "df766809e0": "Collapse Pane", "cff67afad1": "Copy Context" diff --git a/src/renderer/src/i18n/locales/es.json b/src/renderer/src/i18n/locales/es.json index 9d4cdf90b..bac90e0d9 100644 --- a/src/renderer/src/i18n/locales/es.json +++ b/src/renderer/src/i18n/locales/es.json @@ -2452,7 +2452,6 @@ "0a917b591a": "Pegar", "f3eeb1de13": "Copiar", "c2f0b72b8d": "Insertar", - "openLinkDefaultBrowser": "Abrir en el navegador predeterminado", "925f49f210": "Expandir panel", "df766809e0": "Contraer panel", "cff67afad1": "Copiar contexto" diff --git a/src/renderer/src/i18n/locales/ja.json b/src/renderer/src/i18n/locales/ja.json index 775f4b584..126c29124 100644 --- a/src/renderer/src/i18n/locales/ja.json +++ b/src/renderer/src/i18n/locales/ja.json @@ -2452,7 +2452,6 @@ "0a917b591a": "ペースト", "f3eeb1de13": "コピー", "c2f0b72b8d": "入れる", - "openLinkDefaultBrowser": "既定のブラウザで開く", "925f49f210": "ペインを展開する", "df766809e0": "ペインを折りたたむ", "cff67afad1": "Copy Context" diff --git a/src/renderer/src/i18n/locales/ko.json b/src/renderer/src/i18n/locales/ko.json index 62132106a..413de5cc0 100644 --- a/src/renderer/src/i18n/locales/ko.json +++ b/src/renderer/src/i18n/locales/ko.json @@ -2452,7 +2452,6 @@ "0a917b591a": "붙여넣기", "f3eeb1de13": "복사", "c2f0b72b8d": "삽입", - "openLinkDefaultBrowser": "기본 브라우저에서 열기", "925f49f210": "창 확장", "df766809e0": "창 축소", "cff67afad1": "Copy Context" diff --git a/src/renderer/src/i18n/locales/zh.json b/src/renderer/src/i18n/locales/zh.json index 41d3bbeb7..94c8cf870 100644 --- a/src/renderer/src/i18n/locales/zh.json +++ b/src/renderer/src/i18n/locales/zh.json @@ -2452,7 +2452,6 @@ "0a917b591a": "粘贴", "f3eeb1de13": "复制", "c2f0b72b8d": "插入", - "openLinkDefaultBrowser": "在默认浏览器中打开", "925f49f210": "展开窗格", "df766809e0": "折叠窗格", "cff67afad1": "复制上下文"