From 6dcae2711dd7f7aa5813826dfc4aa416fee2abc9 Mon Sep 17 00:00:00 2001 From: Smit Barmase Date: Wed, 3 Sep 2025 03:00:09 +0530 Subject: [PATCH] terminal: Fix not able to select text during continuous output (#37395) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #37211 Regressed in https://github.com/zed-industries/zed/pull/33305 Every time the terminal updates, we emit `SearchEvent::MatchesInvalidated` to trigger a re-run of the buffer search, which calls `clear_matches` to drop stale results. https://github.com/zed-industries/zed/pull/33305 PR also cleared the selection when clearing matches, which caused this issue. We could fix it by only clearing matches and selection when they’re non-empty, but it’s better to not clear the selection at all. This matches how the editor behaves and keeps it consistent. This PR reverts that part of code. Release Notes: - Fixed an issue where text selection was lost during continuous terminal output. --- crates/terminal/src/terminal.rs | 5 ----- crates/terminal_view/src/terminal_view.rs | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rs index c0c663f4987fd08aecbcc58b234333fef20a981c..a8b1fcf0f2a31cbd80612d2e19506d38d52fe0af 100644 --- a/crates/terminal/src/terminal.rs +++ b/crates/terminal/src/terminal.rs @@ -1141,11 +1141,6 @@ impl Terminal { } } - pub fn clear_matches(&mut self) { - self.matches.clear(); - self.set_selection(None); - } - pub fn select_matches(&mut self, matches: &[RangeInclusive]) { let matches_to_select = self .matches diff --git a/crates/terminal_view/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rs index 9e479464af224c4d85119d6ca2e0b25c360f9c3d..2548a7c24460be3161147b69e30c6191ba5dd2e6 100644 --- a/crates/terminal_view/src/terminal_view.rs +++ b/crates/terminal_view/src/terminal_view.rs @@ -1523,7 +1523,7 @@ impl SearchableItem for TerminalView { /// Clear stored matches fn clear_matches(&mut self, _window: &mut Window, cx: &mut Context) { - self.terminal().update(cx, |term, _| term.clear_matches()) + self.terminal().update(cx, |term, _| term.matches.clear()) } /// Store matches returned from find_matches somewhere for rendering