opencode icon indicating copy to clipboard operation
opencode copied to clipboard

fix(tui): support clipboard image paste with proper filename on WSL2

Open mmdsnb opened this issue 2 days ago • 2 comments

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

mmdsnb avatar Jan 13 '26 13:01 mmdsnb