fix: insert native file path when dropping or pasting non-image files#885
Open
mfazekas wants to merge 1 commit intopingdotgg:mainfrom
Open
fix: insert native file path when dropping or pasting non-image files#885mfazekas wants to merge 1 commit intopingdotgg:mainfrom
mfazekas wants to merge 1 commit intopingdotgg:mainfrom
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
d912835 to
3698cab
Compare
Previously, only image files could be attached to the composer. Dropping or pasting any other file type (e.g. .riv, .csv, .json) silently failed with an "unsupported file type" error, making it impossible to reference data or asset files by path. Closes pingdotgg#557. Implementation ────────────── contracts/ipc.ts Added getPathForFile(file) to the DesktopBridge interface. preload.ts Exposed webUtils.getPathForFile(file) via contextBridge. Electron's sandbox blocks the legacy file.path property on File objects; the webUtils API (available since Electron 32) is the official replacement. ComposerPromptEditor Added insertText(text) to ComposerPromptEditorHandle. Uses Lexical's native selection.insertText() to insert at the real cursor position, which correctly handles existing @mention nodes. Manipulating the plain-text snapshot and calling setPrompt() was not an option: Lexical's editor.update() is async, so a synchronous focusComposer() call after would read a stale snapshotRef and overwrite the inserted text via onChange. ChatView - COMPOSER_FILE_PATH_SEPARATOR constant replaces the magic " " literal. - addComposerAttachments(files) is a new unified helper (placed next to addComposerImages) that partitions files into images and non-images. Images are handled by the existing addComposerImages path. Non-image files have their native path resolved via desktopBridge.getPathForFile (fallback: file.name in non-Electron contexts), auto-quoted when the path contains spaces, joined by COMPOSER_FILE_PATH_SEPARATOR, and inserted into the composer via insertText(). - onComposerDrop and onComposerPaste both delegate to addComposerAttachments, eliminating the duplicated partition logic. onComposerDrop additionally calls focusComposer() only when no non-image files were dropped, since insertText() focuses the editor internally as a prerequisite for obtaining a Lexical selection. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
3698cab to
61dab45
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Changed
When dropping or pasting non-image files (e.g.
.csv,.json,.txt,.riv) onto the chat composer, their native filesystem path is now inserted at the cursor position instead of being silently ignored. Fixes #557.addComposerAttachmentshelper partitions files into images and non-images. BothonComposerDropandonComposerPastedelegate to it. Non-image paths are auto-quoted when containing spaces.insertText(text)using Lexical'sselection.insertText()to insert at the real cursor position, correctly handling @mention nodes.webUtils.getPathForFile(file)via contextBridge (required since Electron's sandbox blocksfile.path).getPathForFiletoDesktopBridgeinterface.Why
Dropping or pasting any non-image file silently failed with an "unsupported file type" error
UI Changes
Checklist
Note
Insert native file paths when dropping or pasting non-image files into the composer
addComposerAttachmentsin ChatView.tsx to split dropped/pasted files into images (handled as before) and non-images (inserted as paths).window.desktopBridge?.getPathForFile(file)(Electron) or fall back tofile.name; paths containing spaces are quoted and joined with a space separator.insertTextAndFocus(text)toComposerPromptEditorHandlein ComposerPromptEditor.tsx, inserting text at the current Lexical selection with automatic focus.getPathForFileondesktopBridgein preload.ts via Electron'swebUtils.getPathForFile.Macroscope summarized 61dab45.