Skip to content

feat: support file drag-and-drop into terminal nodes#163

Merged
DeadWaveWave merged 1 commit intoDeadWaveWave:mainfrom
zuxinrui:feat/terminal-file-drag-drop
Apr 17, 2026
Merged

feat: support file drag-and-drop into terminal nodes#163
DeadWaveWave merged 1 commit intoDeadWaveWave:mainfrom
zuxinrui:feat/terminal-file-drag-drop

Conversation

@zuxinrui
Copy link
Copy Markdown
Contributor

Summary

  • Add drag-and-drop support for files from the system file manager into terminal/agent nodes
  • Dropped files have their absolute paths pasted at the cursor, matching native terminal behavior (GNOME Terminal, iTerm2, Windows Terminal, etc.)
  • Uses Electron's webUtils.getPathForFile() (sandbox-safe) to resolve file paths, with shell-special character escaping via single-quote wrapping
  • Delegates to xterm's terminal.paste() for correct bracketed paste mode handling

Details

Problem: In native terminals, dragging a file into the window pastes its path. In OpenCove, dragging files into agent/terminal nodes had no effect — xterm.js does not handle HTML5 drag-and-drop events, and no custom handler existed.

Changes (3 files, ~40 lines):

File Change
src/.../TerminalNode.tsx Add dragover/drop event listeners on the terminal container DOM element
src/app/preload/index.ts Expose webUtils.getPathForFile() via opencoveApi.filesystem
src/app/preload/index.d.ts Add type declaration for getPathForFile

Design decisions:

  • webUtils.getPathForFile() instead of File.path — the latter returns empty string in sandbox mode
  • terminal.paste() instead of ptyWriteQueue.enqueue() — automatically handles bracketed paste mode
  • stopPropagation() on both events — prevents the canvas-level image import handler from interfering
  • Shell escaping uses single-quote wrapping (handles spaces, $, backticks, etc.)

Test plan

  • Drag a single file → path appears at cursor
  • Drag a file with spaces in path → path is single-quoted
  • Drag multiple files → space-separated paths
  • Drag a directory → path appears (same as file)
  • Drag an image to canvas (not terminal) → existing image import still works
  • Ctrl+V paste still works normally

🤖 Generated with Claude Code

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 11, 2026

CLA assistant check
All committers have signed the CLA.

@DeadWaveWave
Copy link
Copy Markdown
Owner

感谢贡献!PR 还需要处理一下文件冲突问题

@zuxinrui zuxinrui force-pushed the feat/terminal-file-drag-drop branch from 56514c0 to 284e4eb Compare April 15, 2026 14:01
Enable dragging files from the system file manager into terminal/agent
nodes to paste their absolute paths. This mirrors the behavior of native
terminals (GNOME Terminal, iTerm2, etc.) where drag-and-drop inserts the
file path at the cursor.

Uses Electron's `webUtils.getPathForFile()` (sandbox-safe) to resolve
absolute paths, escapes shell-special characters with single-quote
wrapping, and delegates to `terminal.paste()` for correct bracketed
paste mode handling.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@zuxinrui zuxinrui force-pushed the feat/terminal-file-drag-drop branch from fdc90c0 to 3d83559 Compare April 16, 2026 16:53
@zuxinrui
Copy link
Copy Markdown
Contributor Author

@DeadWaveWave 文件冲突已经解决,如果有其他问题请随时message,感谢!

@DeadWaveWave DeadWaveWave merged commit 7f911fb into DeadWaveWave:main Apr 17, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants