Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Move the cursor on search in Terminal if ViMode is active (#33305)

Aleksei Gusev665006c4144c
diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rs
index c3c6de9e53d..86728cc11cf 100644
--- a/crates/terminal/src/terminal.rs
+++ b/crates/terminal/src/terminal.rs
@@ -167,6 +167,7 @@ enum InternalEvent {
// Vi mode events
ToggleViMode,
ViMotion(ViMotion),
+ MoveViCursorToAlacPoint(AlacPoint),
}
///A translation struct for Alacritty to communicate with us from their event loop
@@ -972,6 +973,10 @@ impl Terminal {
term.scroll_to_point(*point);
self.refresh_hovered_word(window);
}
+ InternalEvent::MoveViCursorToAlacPoint(point) => {
+ term.vi_goto_point(*point);
+ self.refresh_hovered_word(window);
+ }
InternalEvent::ToggleViMode => {
self.vi_mode_enabled = !self.vi_mode_enabled;
term.toggle_vi_mode();
@@ -1100,12 +1105,21 @@ impl Terminal {
pub fn activate_match(&mut self, index: usize) {
if let Some(search_match) = self.matches.get(index).cloned() {
self.set_selection(Some((make_selection(&search_match), *search_match.end())));
-
- self.events
- .push_back(InternalEvent::ScrollToAlacPoint(*search_match.start()));
+ if self.vi_mode_enabled {
+ self.events
+ .push_back(InternalEvent::MoveViCursorToAlacPoint(*search_match.end()));
+ } else {
+ self.events
+ .push_back(InternalEvent::ScrollToAlacPoint(*search_match.start()));
+ }
}
}
+ 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
diff --git a/crates/terminal_view/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rs
index 0ec5f816d52..219238496cb 100644
--- a/crates/terminal_view/src/terminal_view.rs
+++ b/crates/terminal_view/src/terminal_view.rs
@@ -1869,7 +1869,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.matches.clear())
+ self.terminal().update(cx, |term, _| term.clear_matches())
}
/// Store matches returned from find_matches somewhere for rendering