[Bug] 桌面版内嵌终端不支持文件拖放:拖文件到 TUI 输入框无任何反应(GUI 聊天输入框正常)
Nobody has claimed this yet.
- Dominant language
- No language data
- Stars
- 22
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
提交前确认 · Pre-submission checklist
- I searched existing issues and confirmed this isn't a duplicate.(已用 拖拽/drag/drop/拖文件/输入框/terminal/终端/附件/Finder/TUI 等关键词检索全部 275 个 open+closed issue,无重复)
- I've read CONTRIBUTING.md.
ℹ️ The dropdown fields below could not be set programmatically. Please select them manually when reviewing:
- Category:
终端 / 输入交互 · Terminal / Input- Agent framework:
不涉及框架 · Not framework-specific- Severity:
影响体验 · Major (works but degraded)- Reproducibility:
必现 · Always
问题描述 · Description
ZCode 桌面版的内嵌终端(跑 zcode TUI 的那块面板)完全不支持文件拖放:从 Finder / 桌面 / 文件树拖文件到终端里的 TUI 输入框(> 提示符那块)时毫无反应——无高亮、无路径粘贴、无附件生成,也没有任何错误提示。
作为对照,GUI 聊天输入框(v4-composer)的文件拖放是完全正常的(拖文件→附件 chip,拖文件夹→附件,从文件树拖→插入 @引用)。官方文档也只描述了聊天输入框的拖放。内嵌终端疑似从未实现该能力(xterm.js 核心不自带文件 drop 处理,需要宿主自行注册监听)。
复现步骤 · Steps to reproduce
- ZCode 桌面版打开任意会话,点击底部「切换终端」打开终端面板(TUI 输入框可见,
>提示符 +bypass permissions on (shift+tab to cycle)底栏)。 - 从 Finder 拖任意文件,悬停在终端区域上 → 无任何放置提示(光标为禁止态/无高亮)。
- 松开鼠标 → 什么都不会发生:路径没有粘贴进 TUI 输入框,也没有附件。
- 对照:把同一个文件拖到 GUI 聊天输入框 → 正常生成附件 chip。
预期行为:拖文件到终端 → 将文件路径粘贴进 TUI 输入框(路径含空格/中文时加引号),多文件以空格连接——即 VS Code 终端的 "drop into terminal" 行为。
环境信息 · Environment
- ZCode Desktop 3.8.1 (3.8.1.5310)
- macOS 15.6 (darwin 25.6.0, Apple Silicon)
根因分析 · Root cause(已定位到代码)
对 3.8.1 的 app.asar 解包分析 + 通过 CDP 派发可信拖放事件(Input.dispatchDragEvent)实测验证:
- 渲染层中 Terminal 组件(初始化 xterm 的地方,
out/renderer/assets/styles-*.js,存在两处变体)在term.open(el)之后只注册了attachCustomKeyEventHandler(⌘C/⌘V)、link provider(http 链接)和主题 MutationObserver——没有在终端容器上注册任何dragover/drop监听。 - 整个渲染层只有 3 个
drop监听器,全部挂在window上用于拖拽覆盖层的显隐复位;xterm.js 核心本身也不处理文件 drop。因此 OS 层拖放事件到达终端区域后被直接丢弃。 - CDP 实测:对 GUI composer 派发可信拖放(
files: [路径])→ drop 事件正常到达、附件 chip 生成 ✓;对终端同样派发 → 事件到达 DOM 但无任何处理器消费,TUI 输入框无变化 ✗。
建议修法 · Suggested fix
在 Terminal 组件 term.open(el) 后注册(已在本机 patched 验证可行):
dragover:preventDefault()+dropEffect='copy'+ 悬停高亮;drop:经 preload 已暴露的window.zcode.getPathForFile(File)(内部即webUtils.getPathForFile)解析本地路径,含空格/中文等字符时用JSON.stringify加引号,然后term.paste(paths.join(' '))粘贴进 TUI 输入框;无files时退回粘贴text/plain(顺带支持纯文本拖入)。
本地按此方案修补后,用可信 CDP 拖放事件验证:中文路径自动带引号("/Users/xx/项目进度表.md")、ASCII 路径裸粘贴、多文件空格连接,均正常进入终端输入。
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the Terminal component around term.open(el) in the renderer assets/styles-*.js variants, then inspect the existing preload exposure of window.zcode.getPathForFile(File). Reproduce with the stated macOS setup and trusted CDP drag events. Done means files dropped on the TUI input become correctly quoted, space-separated paths, with plain-text fallback and no regression to GUI composer drops.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- cli, desktop
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100