GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(tui): improve clipboard paste and drag-and-drop file handling on Linux by RobertWsp · Pull Request #14552 · anomalyco/opencode

Conversation

@RobertWsp

@RobertWsp RobertWsp commented Feb 21, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Issue for this PR

Closes #14555
Also addresses #4668, #6331, #10154

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Fixes TUI paste and drag-and-drop to properly handle multiple file formats and terminal emulators on Linux.

clipboard.ts — Dynamic MIME discovery: The previous implementation hardcoded image/png as the only clipboard format. This replaces it with a priority-ordered probe (PNG → JPEG → WebP → GIF → BMP) that reads the first available format from the system clipboard via xclip/xsel. Falls back gracefully when no image is available.

prompt/index.tsx — Rewritten onPaste handler: The core change. When text is pasted, the handler now checks if the pasted content looks like file paths before treating it as plain text:

  1. Multi-line paths (newline-separated, from Nautilus/Thunar file managers): splits by newline, validates each line is an existing path via Filesystem.exists(), then routes images to pasteImage() and other files to the new pasteFile().

  2. Single-line space-separated paths (WezTerm DroppedFile format): WezTerm joins multiple dropped file paths with spaces and backslash-escapes spaces within filenames (quote_dropped_files = "SpacesOnly" is the Linux default). A new shellTokens() function parses this format by splitting on unescaped spaces and unescaping \ → .

  3. Single file path: detected with synchronous existsSync() check for fast-path routing.

  4. pasteFile(): new function that handles non-image attachments (PDFs, SVGs, code files) by creating [File: name.ext] virtual tokens, and directories as [Dir: dirname/].

Critical fix — synchronous event.preventDefault(): onPaste is async, but event.preventDefault() must be called before any await to prevent the browser's default paste behavior (inserting raw text) from executing during the async gap. This is called immediately after the synchronous heuristic check (all tokens look like paths), before any filesystem I/O.

The all-or-nothing validation ensures regular text paste is unaffected: if ANY token doesn't look like a path or doesn't exist on disk, the entire paste falls through to normal text insertion.

How did you verify your code works?

Tested on Zorin OS 18 (Ubuntu Noble, X11) with WezTerm nightly 20260117-154428-05343b38:

  • Multi-file drag-and-drop from Nautilus → only virtual tokens appear, no raw paths
  • Single file drag-and-drop → only virtual token appears
  • Filenames with spaces and special characters (e.g. Projeto (12).png) parsed correctly
  • Clipboard paste (Ctrl+V) with PNG and JPEG images
  • Regular text paste unaffected
  • Non-existent paths fall through to text paste

Screenshots / recordings

N/A — TUI terminal behavior, not a visual UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

dav1lex reacted with heart emoji
All reactions
  • ❤️ 1 reaction
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Feb 21, 2026
@github-actions

github-actions Bot commented Feb 21, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@RobertWsp RobertWsp mentioned this pull request Feb 21, 2026
[FEATURE]: improve TUI clipboard paste and drag-and-drop file handling on Linux #14555
Closed
1 task done
@github-actions github-actions Bot removed needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Feb 21, 2026
@github-actions

github-actions Bot commented Feb 21, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

RobertWsp added 7 commits February 23, 2026 10:29
@RobertWsp
fix(tui): support all image MIME types in Linux clipboard read
5b84190
@RobertWsp
feat(tui): rewrite onPaste handler for multi-file paste and drag-and-…
cf73f1c
…drop
@RobertWsp
fix(tui): call preventDefault synchronously in multi-file paste handler
a1c0a74
event.preventDefault() must be called synchronously before yielding
to the event loop. The previous code called it after awaiting
Filesystem.exists(), allowing the browser default paste to insert raw
file paths into the textarea alongside the virtual extmarks.

Fix: add a synchronous heuristic check (paths start with /, ~/, or
file://) to call preventDefault() immediately, then validate existence
asynchronously. If async validation fails, manually insert text as
fallback since the default paste was already prevented.
@RobertWsp
fix(tui): route single non-image file paths to pasteFile handler
7ce20ee
Single file paths for PDFs, code files, and directories were falling
through to the text handler because only image MIME types were checked.
Uses existsSync for synchronous preventDefault before any await.
@RobertWsp
feat(tui): handle WezTerm space-separated drag-and-drop file paths
abc1130
WezTerm sends dropped files as space-separated paths with backslash-
escaped spaces (quote_dropped_files=SpacesOnly), not newline-separated.
Add shellTokens() parser to handle all WezTerm quoting modes and
integrate it into onPaste so multi-file DnD routes to pasteImage/
pasteFile correctly. Also removes debug logging from prior session.
@RobertWsp
fix(tui): call preventDefault synchronously in shell-token DnD handler
88b21fa
Move event.preventDefault() before await in the WezTerm space-separated
DnD branch to prevent raw path text from being inserted during the async
gap. Add text fallback when file existence check fails.
@RobertWsp
chore: remove working files not intended for upstream
bf45dca
@RobertWsp
RobertWsp force-pushed the feat/tui-paste-and-drop branch from b70f398 to bf45dca Compare February 23, 2026 13:30
@github-actions github-actions Bot mentioned this pull request Feb 23, 2026
feat(tui): add import dialogs for text and images #14796
Closed
@github-actions github-actions Bot mentioned this pull request Mar 10, 2026
feat(opencode): Add PDF attachment Drag and Drop #16926
Merged
4 of 6 tasks
inakineitor pushed a commit to inakineitor/ai-tui that referenced this pull request Mar 10, 2026
@claude
fix(clipboard): support multiple image MIME types on Linux
4401636
Instead of only checking for image/png, now queries available MIME types
and tries png, jpeg, webp, gif, bmp in priority order for both Wayland
and X11 clipboard backends.

Upstream: anomalyco/opencode#14552

https://claude.ai/code/session_01R2NB6YZNAFe57T3uhSCGo9
This was referenced Mar 12, 2026
fix(opencode): improve linux clipboard error handling and add nix dependencies #17258
Closed
feat(tui): improve drag-drop image path handling for tool access #17489
Closed
@github-actions github-actions Bot mentioned this pull request Mar 30, 2026
fix(app): prefer dropped files over file URIs #19994
Closed
@bk-bf bk-bf mentioned this pull request Apr 4, 2026
fix: improve Linux clipboard image paste support openchamber/openchamber#843
Closed
@github-actions github-actions Bot mentioned this pull request Apr 8, 2026
fix: save pasted clipboard images to temp files to support MCP tools (#14673) #21547
Closed
3 of 6 tasks
@opencode-agent
opencode-agent Bot force-pushed the dev branch from 2f2ed11 to 9f201d6 Compare April 16, 2026 21:55
This was referenced Apr 20, 2026
fix(opencode): validate clipboard content type on Linux #23459
Closed
fix(opencode): validate clipboard content type on Linux #23552
Closed
fix: preserve image attachment file paths #23802
Closed
@github-actions

github-actions Bot commented Apr 25, 2026

Copy link
Copy Markdown
Contributor

Closing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot closed this Apr 25, 2026
@Nigmat-future Nigmat-future mentioned this pull request Jun 11, 2026
[FEATURE]: Drag-and-drop external files should offer Insert Path mode — reference files by path instead of inlining content #31939
Closed
1 task done
@Hollow1838 Hollow1838 mentioned this pull request Aug 4, 2026
[Bug] Clipboard functionality fails in WSL environment due to missing Windows executable paths #9999
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[FEATURE]: improve TUI clipboard paste and drag-and-drop file handling on Linux

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@RobertWsp
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.