diff --git a/src/renderer/src/components/editor/rich-markdown-terminal-path-paste.test.ts b/src/renderer/src/components/editor/rich-markdown-terminal-path-paste.test.ts index faf6b14ce39..55a0aaa1d8b 100644 --- a/src/renderer/src/components/editor/rich-markdown-terminal-path-paste.test.ts +++ b/src/renderer/src/components/editor/rich-markdown-terminal-path-paste.test.ts @@ -68,6 +68,16 @@ describe('rich markdown terminal path paste', () => { ).toBe(false) }) + it('does not treat a bare-domain auto-linked URL as a Windows drive path', () => { + expect( + shouldPasteTerminalWindowsPathAsPlainText({ + plainText: 'Heading\n\nVisit https://acme.com for details.', + htmlText: + '
Visit https://acme.com for details.
' + }) + ).toBe(false) + }) + it('inserts the plain clipboard text before TipTap can preserve broken link metadata', () => { const { editor, inserted } = makeEditor() const text = 'C:\\Users\\neil\\.claude\\CLAUDE.md' diff --git a/src/renderer/src/components/editor/rich-markdown-terminal-path-paste.ts b/src/renderer/src/components/editor/rich-markdown-terminal-path-paste.ts index cfdb7f422fd..5db624f4acc 100644 --- a/src/renderer/src/components/editor/rich-markdown-terminal-path-paste.ts +++ b/src/renderer/src/components/editor/rich-markdown-terminal-path-paste.ts @@ -4,8 +4,11 @@ type ClipboardAnchor = { href: string } +// The drive-letter alternative requires a non-letter boundary before the +// letter so a URL scheme's trailing char (e.g. the "s" in "https://") is not +// mistaken for a "X:/..." drive path, which would discard rich paste formatting. const WINDOWS_ABSOLUTE_PATH_PATTERN = - /(?:[A-Za-z]:[\\/][^\s<>"|?*\r\n]+|\\\\[^\s\\/:*?"<>|\r\n]+\\[^\s\\/:*?"<>|\r\n]+(?:\\[^\s<>"|?*\r\n]+)*)/g + /(?:(?"|?*\r\n]+|\\\\[^\s\\/:*?"<>|\r\n]+\\[^\s\\/:*?"<>|\r\n]+(?:\\[^\s<>"|?*\r\n]+)*)/g function readClipboardText(event: ClipboardEvent, type: string): string { return event.clipboardData?.getData(type) ?? ''