terminal: Fix not able to select text during continuous output (#37395)

Smit Barmase created

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.

Change summary

crates/terminal/src/terminal.rs           | 5 -----
crates/terminal_view/src/terminal_view.rs | 2 +-
2 files changed, 1 insertion(+), 6 deletions(-)

Detailed changes

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<AlacPoint>]) {
         let matches_to_select = self
             .matches

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>) {
-        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