diff options
| author | Jacob Richman <[email protected]> | 2025-07-25 20:26:13 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-07-25 20:26:13 +0000 |
| commit | de968877895a8ae5f0edb83a43b37fa190cc8ec9 (patch) | |
| tree | 5670176f9e197a73fdc40f82b37861238543515d /packages/cli/src/ui/components/shared/text-buffer.ts | |
| parent | 13b09712917c13bf32113aac86c6fbdc31bce187 (diff) | |
Fix bugs breaking drag and drop of files. (#4887)
Co-authored-by: matt korwel <[email protected]>
Diffstat (limited to 'packages/cli/src/ui/components/shared/text-buffer.ts')
| -rw-r--r-- | packages/cli/src/ui/components/shared/text-buffer.ts | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/packages/cli/src/ui/components/shared/text-buffer.ts b/packages/cli/src/ui/components/shared/text-buffer.ts index 7eb3088a..31db1f14 100644 --- a/packages/cli/src/ui/components/shared/text-buffer.ts +++ b/packages/cli/src/ui/components/shared/text-buffer.ts @@ -1023,26 +1023,27 @@ export function useTextBuffer({ }, [visualCursor, visualScrollRow, viewport]); const insert = useCallback( - (ch: string): void => { + (ch: string, { paste = false }: { paste?: boolean } = {}): void => { if (/[\n\r]/.test(ch)) { dispatch({ type: 'insert', payload: ch }); return; } const minLengthToInferAsDragDrop = 3; - if (ch.length >= minLengthToInferAsDragDrop && !shellModeActive) { - let potentialPath = ch; - if ( - potentialPath.length > 2 && - potentialPath.startsWith("'") && - potentialPath.endsWith("'") - ) { - potentialPath = ch.slice(1, -1); + if ( + ch.length >= minLengthToInferAsDragDrop && + !shellModeActive && + paste + ) { + let potentialPath = ch.trim(); + const quoteMatch = potentialPath.match(/^'(.*)'$/); + if (quoteMatch) { + potentialPath = quoteMatch[1]; } potentialPath = potentialPath.trim(); if (isValidPath(unescapePath(potentialPath))) { - ch = `@${potentialPath}`; + ch = `@${potentialPath} `; } } @@ -1203,7 +1204,7 @@ export function useTextBuffer({ backspace(); else if (key.name === 'delete' || (key.ctrl && key.name === 'd')) del(); else if (input && !key.ctrl && !key.meta) { - insert(input); + insert(input, { paste: key.paste }); } }, [newline, move, deleteWordLeft, deleteWordRight, backspace, del, insert], @@ -1306,7 +1307,7 @@ export interface TextBuffer { /** * Insert a single character or string without newlines. */ - insert: (ch: string) => void; + insert: (ch: string, opts?: { paste?: boolean }) => void; newline: () => void; backspace: () => void; del: () => void; |
