feat: 拖拽文件夹到输入框自动插入路径文本#5447
Conversation
When a folder is dragged from the OS file manager into the composer input area via the Wails native file-drop bridge, its absolute path is now inserted as plain text in the textarea - rather than erroring or adding an attachment. Changes: - Go (app.go): outside-workspace directories now return DroppedItem with Kind="folder" and the original absolute path instead of erroring - Frontend (types.ts): add "folder" to DroppedItem.kind union - Frontend (Composer.tsx): handle kind="folder" by inserting the path as text via setTextCaretEnd, with automatic spacing - Test (attach_dropped_test.go): add TestAttachDroppedOutsideWorkspaceDirReturnsFolder Closes: esengine#5370
…ng it The onFilesDropped callback captures attachDroppedPaths from the first render (empty deps []), so in the closure is always the initial empty string. This caused folder path drops to overwrite any existing input content. Fix: read current textarea value from taRef.current.value (the live DOM) instead of the stale closure variable.
Addresses all issues found by multi-review (pr-review + ponytail-review + review): 1. [Blocker] Windows: filepath.ToSlash() on dropped folder path for cross-platform consistency with workspaceRelativeIn & SaveAttachmentFile 2. [Blocker] Race condition: use textRef (already synced with text state) instead of stale closure 'text' or taRef DOM value; update textRef immediately within the loop to prevent interleaved drops from colliding 3. [Blocker] textarea-unmount fallback: textRef.current always holds the latest value, never the stale initial empty string 4. [Warning] DroppedItem.Kind comment updated to include "folder" 5. [Warning] DroppedItem.IsDir set to true for folder kind 6. [Warning] Mock AttachDropped now returns kind="folder" for paths without a file extension (dev-only heuristic)
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: acd7980a62
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const currentText = textRef.current; | ||
| const sep = currentText.length > 0 && !currentText.endsWith(" ") ? " " : ""; | ||
| const next = currentText + sep + item.path + " "; | ||
| textRef.current = next; | ||
| setTextCaretEnd(next); |
There was a problem hiding this comment.
Insert dropped folders into the source draft
When a folder drop is still awaiting app.AttachDropped and the user switches tabs/sessions, this branch appends to textRef.current and calls setTextCaretEnd, which always mutates the currently active composer. The surrounding attachment/workspace paths deliberately use sourceDraftKey so async drop results land in the draft where the drop started; folders now leak the path into the newly active draft and leave the original draft unchanged in that scenario.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
已修复。在插入前检查 activeDraftKeyRef.current !== sourceDraftKey,如果用户已切换会话则跳过插入。commit 105c86b
| if got.Path != outsideDir { | ||
| t.Fatalf("got path=%q, want %q (the original absolute path)", got.Path, outsideDir) |
There was a problem hiding this comment.
Normalize the expected folder path in the new test
When this desktop package is tested on Windows, outsideDir contains backslashes from filepath.Join, but AttachDropped intentionally returns filepath.ToSlash(path) for folders, so this assertion fails even though the implementation did what the production code now specifies. Compare against filepath.ToSlash(outsideDir) (or otherwise normalize both sides) to keep the test portable for Windows desktop development.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
已修复。断言改为 filepath.ToSlash(outsideDir),Windows 上也能正常工作。commit 105c86b
…lization Addresses 2 Codex inline review comments on PR esengine#5447: 1. Composer.tsx: check activeDraftKeyRef before inserting folder path text to prevent leaking into the wrong session when the user switches tabs mid-drop (follows the same pattern as attachments). 2. attach_dropped_test.go: compare against filepath.ToSlash(outsideDir) so the test passes on Windows where filepath.Join produces backslashes but AttachDropped now returns ToSlash'd paths.
Summary
从 Finder 拖拽文件夹到 Composer 输入框区域时,自动将文件夹的绝对路径作为纯文本插入输入框,而不是报错或添加为附件。
Changes
DroppedItem{Kind:"folder", Path, IsDir:true},使用filepath.ToSlash确保 Windows 兼容DroppedItem.kind增加"folder"类型attachDroppedPaths中新增kind==="folder"分支,用textRef追加路径文本到输入框(支持连续拖拽、不覆盖已有文本)TestAttachDroppedOutsideWorkspaceDirReturnsFolder覆盖新路径Review
wails build编译通过Refs #5370
Note: this PR covers the folder-drag portion of #5370 only; the font-size/custom scaling request remains open for follow-up.