Skip to content

Conversation

@mmdsnb
Copy link

@mmdsnb mmdsnb commented Jan 13, 2026

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

- Add support for copying image files from Windows file manager (Ctrl+C)
- Automatically convert Windows paths to WSL paths (D:\... -> /mnt/d/...)
- Extract and display only filename instead of full path
- Fix onPaste event handling to prevent duplicate text insertion
- Add FileDropList detection in PowerShell clipboard script

Fixes issue where pasted images showed full Windows path instead of filename
in WSL2 terminal environment.
@github-actions
Copy link
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.

@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant