Skip to content

fix(tui): disable mouse capture to restore native text selection#348

Open
coder-movers wants to merge 1 commit into
SaladDay:mainfrom
coder-movers:fix/tui-mouse-capture-blocks-selection
Open

fix(tui): disable mouse capture to restore native text selection#348
coder-movers wants to merge 1 commit into
SaladDay:mainfrom
coder-movers:fix/tui-mouse-capture-blocks-selection

Conversation

@coder-movers

@coder-movers coder-movers commented Jul 14, 2026

Copy link
Copy Markdown

What

Stop enabling mouse capture when the TUI starts (and when it is reactivated after a handoff). Terminal-native drag-to-select and copy work again while the TUI is running.

Why

TuiTerminal::new and activate_best_effort in src/cli/tui/terminal.rs run EnableMouseCapture alongside EnterAlternateScreen. While capture is active the terminal emulator forwards mouse events to the process instead of performing native selection, so users could not select or copy any on-screen text from within the TUI.

The scroll-wheel-to-arrow mapping that previously consumed those events was already removed in ff9dfb2 (fix(tui): prevent long-list scroll stalls), so EnableMouseCapture now has no consumer yet still blocks selection. This PR drops the capture calls from the terminal enter/restore paths.

Why not keep capture and implement in-app selection instead: an app-drawn selection highlight is just rendered cells, not the terminal's selection, so Ctrl+C / Ctrl+Shift+C would still copy nothing useful. The app would have to write the clipboard itself (a new dependency or per-OS shell-out, with WSL2 needing clip.exe). Terminal-native selection is the only way to get copy via the terminal's existing keybindings without that cost, and it requires capture off.

Closes #347.

Change

  • src/cli/tui/terminal.rs: remove the crossterm::event::{DisableMouseCapture, EnableMouseCapture} import and the four EnableMouseCapture / DisableMouseCapture arguments from the execute! calls in new, restore_stdout_best_effort, restore_best_effort, and activate_best_effort. EnterAlternateScreen / LeaveAlternateScreen, raw mode, and cursor show/hide are unchanged.

No change to mod.rs or tests.rs is needed on top of main: the Event::Mouse arm and the MouseEventKind import in mod.rs were already removed by ff9dfb2, and tests.rs already imports MouseEventKind directly.

Tradeoff

This is the opposite direction from #342, which requests mouse click support and needs EnableMouseCapture kept. Under crossterm, capture is all-or-nothing: in-app click hit-testing and terminal-native selection cannot coexist. This PR prioritizes copy-paste; if #342 is implemented later it should be opt-in rather than the default, or accept that selection is unavailable while active.

Testing

cd src-tauri && cargo test --lib cli::tui
# 1316 passed; 0 failed

cargo fmt --check is clean.

EnableMouseCapture is still run on TUI startup and reactivation, which makes
the terminal forward mouse events to the process and disables native
drag-to-select and copy. The scroll-wheel-to-arrow mapping that previously
consumed those events was already removed (ff9dfb2), so the capture now has no
consumer yet still blocks selection. Drop EnableMouseCapture and
DisableMouseCapture from the terminal enter and restore paths.

Closes SaladDay#347
@coder-movers coder-movers force-pushed the fix/tui-mouse-capture-blocks-selection branch from 878c843 to 37337a3 Compare July 14, 2026 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TUI captures the mouse, blocking native text selection/copy

1 participant