Skip to content

fix: insert native file path when dropping or pasting non-image files#885

Open
mfazekas wants to merge 1 commit intopingdotgg:mainfrom
mfazekas:fix/non-image-drop-paste
Open

fix: insert native file path when dropping or pasting non-image files#885
mfazekas wants to merge 1 commit intopingdotgg:mainfrom
mfazekas:fix/non-image-drop-paste

Conversation

@mfazekas
Copy link

@mfazekas mfazekas commented Mar 11, 2026

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.

  • ChatView: New addComposerAttachments helper partitions files into images and non-images. Both onComposerDrop and onComposerPaste delegate to it. Non-image paths are auto-quoted when containing spaces.
  • ComposerPromptEditor: Added insertText(text) using Lexical's selection.insertText() to insert at the real cursor position, correctly handling @mention nodes.
  • preload.ts: Exposed webUtils.getPathForFile(file) via contextBridge (required since Electron's sandbox blocks file.path).
  • contracts/ipc.ts: Added getPathForFile to DesktopBridge interface.

Why

Dropping or pasting any non-image file silently failed with an "unsupported file type" error

UI Changes

before
after

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

Note

Insert native file paths when dropping or pasting non-image files into the composer

  • Adds addComposerAttachments in ChatView.tsx to split dropped/pasted files into images (handled as before) and non-images (inserted as paths).
  • Non-image file paths are resolved via window.desktopBridge?.getPathForFile(file) (Electron) or fall back to file.name; paths containing spaces are quoted and joined with a space separator.
  • Adds insertTextAndFocus(text) to ComposerPromptEditorHandle in ComposerPromptEditor.tsx, inserting text at the current Lexical selection with automatic focus.
  • Exposes getPathForFile on desktopBridge in preload.ts via Electron's webUtils.getPathForFile.

Macroscope summarized 61dab45.

@mfazekas mfazekas marked this pull request as draft March 11, 2026 06:26
@coderabbitai
Copy link

coderabbitai bot commented Mar 11, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 854a1ec2-2e6c-4c3f-bf81-333b263223c2

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added the vouch:unvouched PR author is not yet trusted in the VOUCHED list. label Mar 11, 2026
@mfazekas mfazekas force-pushed the fix/non-image-drop-paste branch from d912835 to 3698cab Compare March 11, 2026 06:31
@mfazekas mfazekas marked this pull request as ready for review March 11, 2026 06:51
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>
@mfazekas mfazekas force-pushed the fix/non-image-drop-paste branch from 3698cab to 61dab45 Compare March 11, 2026 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Restricted to only attach image files?

1 participant