Skip to content

Commit 5d12dcd

Browse files
Steven Voclaude
authored andcommitted
Address CodeRabbit feedback: only intercept file drops
- Add isFileDrop helper to check if drag contains files - Only preventDefault for file drops, allow text/URL drops through - Remove debug console.log statements - Improve path quoting to handle special shell characters (spaces, quotes) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 36fc123 commit 5d12dcd

1 file changed

Lines changed: 17 additions & 25 deletions

File tree

frontend/app/view/term/term.tsx

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -350,64 +350,56 @@ const TerminalView = ({ blockId, model }: ViewComponentProps<TermViewModel>) =>
350350
const termBg = computeBgStyleFromMeta(blockData?.meta);
351351

352352
// Handle drag and drop
353+
// Helper to check if drag event contains files
354+
const isFileDrop = (e: React.DragEvent): boolean => {
355+
return e.dataTransfer?.types?.includes("Files") ?? false;
356+
};
357+
353358
const handleDragOver = React.useCallback((e: React.DragEvent) => {
359+
if (!isFileDrop(e)) return;
354360
e.preventDefault();
355361
e.stopPropagation();
356-
// Indicate that we can accept the drop
357362
e.dataTransfer.dropEffect = "copy";
358363
}, []);
359364

360365
const handleDrop = React.useCallback((e: React.DragEvent) => {
366+
if (!isFileDrop(e)) return;
361367
e.preventDefault();
362368
e.stopPropagation();
363369

364-
// Get files from the drop
365370
const files = Array.from(e.dataTransfer.files);
366-
if (files.length === 0) {
367-
return;
368-
}
369-
370-
console.log("Drop files:", files);
371+
if (files.length === 0) return;
371372

372-
// Get the file path(s) using the Electron API
373+
// Get file paths using Electron API
373374
const paths = files.map((file: File) => {
374375
try {
375-
// Use the exposed Electron API to get the full path
376376
const fullPath = getApi().getPathForFile(file);
377-
console.log("File:", file.name, "-> Full path:", fullPath);
377+
// Quote paths with spaces or special shell characters
378+
if (/[\s'"]/.test(fullPath)) {
379+
return `"${fullPath}"`;
380+
}
378381
return fullPath;
379382
} catch (err) {
380383
console.error("Could not get path for file:", file.name, err);
381384
return file.name;
382385
}
383386
});
384387

385-
console.log("Paths to insert:", paths);
386-
387-
// Insert the path(s) into the terminal
388-
// If multiple files, separate with spaces and quote if necessary
389-
const pathString = paths.map(path => {
390-
// Quote paths that contain spaces
391-
if (path.includes(" ")) {
392-
return `"${path}"`;
393-
}
394-
return path;
395-
}).join(" ");
396-
397-
console.log("Final path string:", pathString);
398-
399-
// Send the path to the terminal
388+
// Send space-separated paths to terminal
389+
const pathString = paths.join(" ");
400390
if (model.termRef.current && pathString) {
401391
model.sendDataToController(pathString);
402392
}
403393
}, [model]);
404394

405395
const handleDragEnter = React.useCallback((e: React.DragEvent) => {
396+
if (!isFileDrop(e)) return;
406397
e.preventDefault();
407398
e.stopPropagation();
408399
}, []);
409400

410401
const handleDragLeave = React.useCallback((e: React.DragEvent) => {
402+
if (!isFileDrop(e)) return;
411403
e.preventDefault();
412404
e.stopPropagation();
413405
}, []);

0 commit comments

Comments
 (0)