[PR #8209] fix(tui): support clipboard image paste with proper filename on WSL2 #12657

Open
opened 2026-02-16 18:17:33 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/8209

State: open
Merged: No


Summary

Fixes clipboard image pasting in WSL2 terminal environment. When users copy image files from Windows file manager and paste into OpenCode TUI, the full Windows path (e.g., D:\temp\image.png) was being displayed instead of just the filename.

Changes

1. Enhanced Clipboard Reading (clipboard.ts)

  • Added support for ContainsFileDropList() to detect copied image files on Windows
  • Automatically extract filename from Windows file paths
  • Convert Windows paths to WSL paths (D:\.../mnt/d/...)
  • Return filename in Clipboard.Content interface

2. Fixed Paste Event Handling (prompt/index.tsx)

  • Call event.preventDefault() immediately in onPaste to prevent default text insertion
  • Check clipboard for images before processing pasted text
  • Manually handle text insertion for all paste scenarios
  • Use extracted filename instead of "clipboard" label

Testing

Tested on WSL2 with Windows Terminal:

  1. Copy image file from Windows file manager (Ctrl+C) → Paste (Ctrl+V)
  2. Drag image file from file manager to terminal window
  3. Copy image from application (e.g., browser) → Paste
  4. Normal text pasting still works correctly

Before

D:\temp\ScreenShot_2026-01-13_191354_854.png [Image 1]

After

ScreenShot_2026-01-13_191354_854.png [Image 1]

Technical Details

  • PowerShell script now outputs FILEPATH: prefix to indicate file path source
  • Path conversion only happens in WSL environment (detected via os.release())
  • No performance impact on normal text pasting (< 500 chars check optimization)

Fixes #issue-number-if-exists

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/8209 **State:** open **Merged:** No --- ## Summary Fixes clipboard image pasting in WSL2 terminal environment. When users copy image files from Windows file manager and paste into OpenCode TUI, the full Windows path (e.g., `D:\temp\image.png`) was being displayed instead of just the filename. ## Changes ### 1. Enhanced Clipboard Reading (`clipboard.ts`) - Added support for `ContainsFileDropList()` to detect copied image files on Windows - Automatically extract filename from Windows file paths - Convert Windows paths to WSL paths (`D:\...` → `/mnt/d/...`) - Return filename in `Clipboard.Content` interface ### 2. Fixed Paste Event Handling (`prompt/index.tsx`) - Call `event.preventDefault()` immediately in `onPaste` to prevent default text insertion - Check clipboard for images before processing pasted text - Manually handle text insertion for all paste scenarios - Use extracted filename instead of "clipboard" label ## Testing Tested on WSL2 with Windows Terminal: 1. ✅ Copy image file from Windows file manager (Ctrl+C) → Paste (Ctrl+V) 2. ✅ Drag image file from file manager to terminal window 3. ✅ Copy image from application (e.g., browser) → Paste 4. ✅ Normal text pasting still works correctly ## Before ``` D:\temp\ScreenShot_2026-01-13_191354_854.png [Image 1] ``` ## After ``` ScreenShot_2026-01-13_191354_854.png [Image 1] ``` ## Technical Details - PowerShell script now outputs `FILEPATH:` prefix to indicate file path source - Path conversion only happens in WSL environment (detected via `os.release()`) - No performance impact on normal text pasting (< 500 chars check optimization) Fixes #issue-number-if-exists
yindo added the pull-request label 2026-02-16 18:17:33 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12657