From 84124c60db66416748e2f0971f2c232a0dbad5fe Mon Sep 17 00:00:00 2001 From: feeiyu <158308373+feeiyu@users.noreply.github.com> Date: Mon, 14 Jul 2025 19:04:54 +0800 Subject: [PATCH] Fix cannot select in terminal when copy_on_select is enabled (#34131) Closes #33989 ![terminal_select](https://github.com/user-attachments/assets/5027d2f2-f2b3-43a4-8262-3c266fdc5256) Release Notes: - N/A --- crates/terminal/src/terminal.rs | 22 +++++++++++----------- crates/terminal_view/src/terminal_view.rs | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rs index 72307b697a..6e359414d7 100644 --- a/crates/terminal/src/terminal.rs +++ b/crates/terminal/src/terminal.rs @@ -162,7 +162,8 @@ enum InternalEvent { UpdateSelection(Point), // Adjusted mouse position, should open FindHyperlink(Point, bool), - Copy, + // Whether keep selection when copy + Copy(Option), // Vi mode events ToggleViMode, ViMotion(ViMotion), @@ -931,13 +932,13 @@ impl Terminal { } } - InternalEvent::Copy => { + InternalEvent::Copy(keep_selection) => { if let Some(txt) = term.selection_to_string() { cx.write_to_clipboard(ClipboardItem::new_string(txt)); - - let settings = TerminalSettings::get_global(cx); - - if !settings.keep_selection_on_copy { + if !keep_selection.unwrap_or_else(|| { + let settings = TerminalSettings::get_global(cx); + settings.keep_selection_on_copy + }) { self.events.push_back(InternalEvent::SetSelection(None)); } } @@ -1108,8 +1109,8 @@ impl Terminal { .push_back(InternalEvent::SetSelection(selection)); } - pub fn copy(&mut self) { - self.events.push_back(InternalEvent::Copy); + pub fn copy(&mut self, keep_selection: Option) { + self.events.push_back(InternalEvent::Copy(keep_selection)); } pub fn clear(&mut self) { @@ -1267,8 +1268,7 @@ impl Terminal { } "y" => { - self.events.push_back(InternalEvent::Copy); - self.events.push_back(InternalEvent::SetSelection(None)); + self.copy(Some(false)); return; } @@ -1653,7 +1653,7 @@ impl Terminal { } } else { if e.button == MouseButton::Left && setting.copy_on_select { - self.copy(); + self.copy(Some(true)); } //Hyperlinks diff --git a/crates/terminal_view/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rs index 76ec9dcb25..bad3ebd479 100644 --- a/crates/terminal_view/src/terminal_view.rs +++ b/crates/terminal_view/src/terminal_view.rs @@ -715,7 +715,7 @@ impl TerminalView { ///Attempt to paste the clipboard into the terminal fn copy(&mut self, _: &Copy, _: &mut Window, cx: &mut Context) { - self.terminal.update(cx, |term, _| term.copy()); + self.terminal.update(cx, |term, _| term.copy(None)); cx.notify(); }