opencode
opencode copied to clipboard
fix(tui): support clipboard image paste with proper filename on WSL2
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.Contentinterface
2. Fixed Paste Event Handling (prompt/index.tsx)
- Call
event.preventDefault()immediately inonPasteto 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:
- ✅ Copy image file from Windows file manager (Ctrl+C) → Paste (Ctrl+V)
- ✅ Drag image file from file manager to terminal window
- ✅ Copy image from application (e.g., browser) → Paste
- ✅ 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