diff --git a/src/renderer/src/components/terminal-pane/terminal-link-handlers.test.ts b/src/renderer/src/components/terminal-pane/terminal-link-handlers.test.ts index a5cd51a21..932d80f02 100644 --- a/src/renderer/src/components/terminal-pane/terminal-link-handlers.test.ts +++ b/src/renderer/src/components/terminal-pane/terminal-link-handlers.test.ts @@ -371,6 +371,36 @@ describe('handleOscLink', () => { expect(openFilePathMock).not.toHaveBeenCalled() }) + it('opens Windows absolute OSC link targets that parse as URL schemes', async () => { + setPlatform('Windows') + + handleOscLink( + 'C:\\repo\\src\\index.ts:12:3', + { metaKey: false, ctrlKey: true }, + { + ...deps, + startupCwd: 'C:\\repo', + worktreePath: 'C:\\repo' + } + ) + await flushAsyncWork() + await flushDoubleRaf() + + expect(authorizeExternalPathMock).toHaveBeenCalledWith({ + targetPath: 'C:/repo/src/index.ts' + }) + expect(openFileMock).toHaveBeenCalledWith( + expect.objectContaining({ filePath: 'C:/repo/src/index.ts' }) + ) + expect(setPendingEditorRevealMock).toHaveBeenNthCalledWith(1, null) + expect(setPendingEditorRevealMock).toHaveBeenNthCalledWith(2, { + filePath: 'C:/repo/src/index.ts', + line: 12, + column: 3, + matchLength: 0 + }) + }) + it('opens Windows UNC file URL links from Windows worktrees', async () => { setPlatform('Windows') diff --git a/src/renderer/src/components/terminal-pane/terminal-osc-link-routing.ts b/src/renderer/src/components/terminal-pane/terminal-osc-link-routing.ts index ebcc72dc5..71c4739a7 100644 --- a/src/renderer/src/components/terminal-pane/terminal-osc-link-routing.ts +++ b/src/renderer/src/components/terminal-pane/terminal-osc-link-routing.ts @@ -30,21 +30,37 @@ export function handleOscLink( // without holding a button) extends a selection until the next click/Esc. event?.preventDefault?.() - let parsed: URL - try { - parsed = new URL(rawText) - } catch { + const openDetectedPathLink = (): boolean => { const resolved = resolveTerminalFileLinkText( rawText, deps.startupCwd || deps.worktreePath, deps.terminalHomePath ) - if (resolved) { - openDetectedFilePath(resolved.absolutePath, resolved.line, resolved.column, { - ...deps, - openWithSystemDefault: Boolean(event?.shiftKey) - }) + if (!resolved) { + return false } + openDetectedFilePath(resolved.absolutePath, resolved.line, resolved.column, { + ...deps, + openWithSystemDefault: Boolean(event?.shiftKey) + }) + return true + } + + if ( + isWindowsAbsolutePathLike(rawText) && + isWindowsAbsolutePathLike(deps.startupCwd || deps.worktreePath) && + openDetectedPathLink() + ) { + // Why: `new URL("C:\\path\\file.ts")` succeeds with protocol `c:`; + // Windows OSC links need file-path routing before generic URL parsing. + return + } + + let parsed: URL + try { + parsed = new URL(rawText) + } catch { + openDetectedPathLink() return }