Skip to content

fix(tui): Windows clipboard - use PowerShell directly for text paste#36470

Closed
MysticDevloper wants to merge 3 commits into
anomalyco:devfrom
MysticDevloper:windows-clipboard-fix
Closed

fix(tui): Windows clipboard - use PowerShell directly for text paste#36470
MysticDevloper wants to merge 3 commits into
anomalyco:devfrom
MysticDevloper:windows-clipboard-fix

Conversation

@MysticDevloper

@MysticDevloper MysticDevloper commented Jul 12, 2026

Copy link
Copy Markdown

Problem

  1. Admin terminal paste broken: On Windows Terminal running as Administrator, Ctrl+V paste does not work.
  2. Text shrinking on copy: When copying text from the TUI output (Ctrl+Y or mouse selection), the text visually shrinks because clearSelection() triggers an immediate console redraw.

Root Cause

  1. PowerShell Get-Clipboard can fail in elevated/admin terminal sessions due to session isolation.
  2. renderer.clearSelection() is called synchronously after copy, causing the console to reflow and the selected text to visually collapse.

Fix

clipboard.ts

  • Added Win32 API clipboard read via bun:ffi (user32.dll OpenClipboard/GetClipboardData/GlobalLock) that works in all terminal privilege levels (admin, elevated, UAC)
  • Falls back to PowerShell Get-Clipboard, then clipboardy

selection.ts + app.tsx

  • Added 150ms delay before clearSelection() after copy operations
  • Prevents visual reflow/shrinking when the selection highlight is removed
  • Applies to: selection copy, console copy (Ctrl+Y), and Escape dismiss

Changes

  • packages/tui/src/clipboard.ts — Win32 API clipboard read for admin terminals
  • packages/tui/src/util/selection.ts — Delay clearSelection by 150ms
  • packages/tui/src/app.tsx — Delay console clearSelection by 150ms

Testing

Verified on Windows Terminal (normal + admin) — paste and copy both work without text shrinking.

… let bracketed paste handle text insertion

- Add direct PowerShell Get-Clipboard for Windows text reads (faster than clipboardy)
- prompt.paste command now only handles image paste
- Text paste relies on bracketed paste (onPaste handler) which is instant
- Fixes Ctrl+V paste not working in Windows Terminal
@github-actions github-actions Bot added needs:issue needs:compliance This means the issue will auto-close after 2 hours. labels Jul 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

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.

@github-actions

Copy link
Copy Markdown
Contributor

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

Based on my search, here are related PRs that address similar clipboard/paste functionality (though no exact duplicates):

  1. fix(tui): add plain text paste #34123 - fix(tui): add plain text paste - Directly related to text paste handling in the TUI
  2. fix(tui): support clipboard image paste on Windows via FileDrop format #33507 - fix(tui): support clipboard image paste on Windows via FileDrop format - Windows-specific clipboard image paste support
  3. feat(tui): insert absolute path for unsupported pastes and toast on failure #34307 - feat(tui): insert absolute path for unsupported pastes and toast on failure - Related paste functionality improvements
  4. fix: preserve clipboard image paths for path-based MCP tools #36051 - fix: preserve clipboard image paths for path-based MCP tools - Clipboard path handling
  5. fix(tui): support copying over ssh with set-clipboard on tmux config #30472 - fix(tui): support copying over ssh with set-clipboard on tmux config - Cross-platform clipboard support
  6. fix(cli): Linux clipboard selection #32370 - fix(cli): Linux clipboard selection - Platform-specific clipboard handling

The most relevant is #34123 (plain text paste) as it directly addresses text paste behavior. You should review these PRs to ensure your fix doesn't conflict with or duplicate existing work, particularly around the bracketed paste event handling and PowerShell fallback strategy.

MysticDevloper added 2 commits July 12, 2026 06:07
- Add Win32 API (user32.dll) clipboard read via bun:ffi for admin/elevated terminals
- Keep PowerShell Get-Clipboard as fallback for non-Bun runtimes
- Delay clearSelection by 150ms to prevent visual reflow when copying
- Applies to selection copy, console copy (Ctrl+Y), and Escape dismiss
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Jul 12, 2026
@github-actions github-actions Bot closed this Jul 12, 2026
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