From 37337a3831b98ebd9dda1fddd651de992fd98051 Mon Sep 17 00:00:00 2001 From: coder-movers <1611020661@qq.com> Date: Wed, 15 Jul 2026 02:28:24 +0800 Subject: [PATCH] fix(tui): disable mouse capture to restore native text selection 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 #347 --- src-tauri/src/cli/tui/terminal.rs | 34 +++++++------------------------ 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/src-tauri/src/cli/tui/terminal.rs b/src-tauri/src/cli/tui/terminal.rs index fe0afe3b..2d2dda5e 100644 --- a/src-tauri/src/cli/tui/terminal.rs +++ b/src-tauri/src/cli/tui/terminal.rs @@ -2,9 +2,7 @@ use std::io::{self, Stdout}; use std::sync::Arc; use crossterm::{ - cursor, - event::{DisableMouseCapture, EnableMouseCapture}, - execute, + cursor, execute, terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen}, }; #[cfg(test)] @@ -83,12 +81,7 @@ fn restore_stdout_best_effort(stdout: &mut Stdout) -> Result<(), AppError> { record_err(&mut first_err, e); } - if let Err(e) = execute!( - stdout, - cursor::Show, - LeaveAlternateScreen, - DisableMouseCapture - ) { + if let Err(e) = execute!(stdout, cursor::Show, LeaveAlternateScreen) { record_err(&mut first_err, e); } @@ -111,12 +104,7 @@ impl TuiTerminal { pub fn new() -> Result { let mut stdout = io::stdout(); enable_raw_mode().map_err(terminal_error)?; - if let Err(e) = execute!( - stdout, - EnterAlternateScreen, - EnableMouseCapture, - cursor::Hide - ) { + if let Err(e) = execute!(stdout, EnterAlternateScreen, cursor::Hide) { let _ = restore_stdout_best_effort(&mut stdout); return Err(terminal_error(e)); } @@ -251,12 +239,8 @@ impl TuiTerminal { match &mut self.terminal { TerminalHandle::Stdout(terminal) => { - if let Err(e) = execute!( - terminal.backend_mut(), - cursor::Show, - LeaveAlternateScreen, - DisableMouseCapture - ) { + if let Err(e) = execute!(terminal.backend_mut(), cursor::Show, LeaveAlternateScreen) + { record_err(&mut first_err, e); } let _ = terminal.show_cursor(); @@ -296,12 +280,8 @@ impl TuiTerminal { match &mut self.terminal { TerminalHandle::Stdout(terminal) => { - if let Err(e) = execute!( - terminal.backend_mut(), - EnterAlternateScreen, - EnableMouseCapture, - cursor::Hide - ) { + if let Err(e) = execute!(terminal.backend_mut(), EnterAlternateScreen, cursor::Hide) + { record_err(&mut first_err, e); }