From 142f84efb955a9fa59f4205ec3a6db3964c5f433 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Wed, 15 Jul 2020 21:27:32 +0000 Subject: Add support for searching without vi mode This implements search without vi mode by using the selection to track the active search match and advancing it on user input. The keys to go to the next or previous match are not configurable and are bound to enter and shift enter based on Firefox's behavior. Fixes #3937. --- alacritty/src/input.rs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'alacritty/src/input.rs') diff --git a/alacritty/src/input.rs b/alacritty/src/input.rs index 58ca42cb..80f3e5d9 100644 --- a/alacritty/src/input.rs +++ b/alacritty/src/input.rs @@ -100,6 +100,7 @@ pub trait ActionContext { fn push_search(&mut self, c: char); fn pop_search(&mut self); fn pop_word_search(&mut self); + fn advance_search_origin(&mut self, direction: Direction); fn search_direction(&self) -> Direction; fn search_active(&self) -> bool; } @@ -224,8 +225,8 @@ impl Execute for Action { ctx.terminal_mut().vi_goto_point(*regex_match.end()); } }, - Action::Search => ctx.start_search(Direction::Right), - Action::SearchReverse => ctx.start_search(Direction::Left), + Action::SearchForward => ctx.start_search(Direction::Right), + Action::SearchBackward => ctx.start_search(Direction::Left), Action::ToggleFullscreen => ctx.window_mut().toggle_fullscreen(), #[cfg(target_os = "macos")] Action::ToggleSimpleFullscreen => ctx.window_mut().toggle_simple_fullscreen(), @@ -359,12 +360,13 @@ impl<'a, T: EventListener, A: ActionContext> Processor<'a, T, A> { #[inline] pub fn mouse_moved(&mut self, position: PhysicalPosition) { + let search_active = self.ctx.search_active(); let size_info = self.ctx.size_info(); let (x, y) = position.into(); let lmb_pressed = self.ctx.mouse().left_button_state == ElementState::Pressed; - if !self.ctx.selection_is_empty() && lmb_pressed { + if !self.ctx.selection_is_empty() && lmb_pressed && !search_active { self.update_selection_scrolling(y); } @@ -405,6 +407,7 @@ impl<'a, T: EventListener, A: ActionContext> Processor<'a, T, A> { let last_term_line = self.ctx.terminal().grid().screen_lines() - 1; if (lmb_pressed || self.ctx.mouse().right_button_state == ElementState::Pressed) && (self.ctx.modifiers().shift() || !self.ctx.mouse_mode()) + && !search_active { // Treat motion over message bar like motion over the last line. let line = min(point.line, last_term_line); @@ -811,9 +814,21 @@ impl<'a, T: EventListener, A: ActionContext> Processor<'a, T, A> { self.ctx.pop_search(); *self.ctx.suppress_chars() = true; }, + (Some(VirtualKeyCode::Return), ModifiersState::SHIFT) + if !self.ctx.terminal().mode().contains(TermMode::VI) => + { + let direction = self.ctx.search_direction().opposite(); + self.ctx.advance_search_origin(direction); + *self.ctx.suppress_chars() = true; + } (Some(VirtualKeyCode::Return), _) | (Some(VirtualKeyCode::J), ModifiersState::CTRL) => { - self.ctx.confirm_search(); + if self.ctx.terminal().mode().contains(TermMode::VI) { + self.ctx.confirm_search(); + } else { + self.ctx.advance_search_origin(self.ctx.search_direction()); + } + *self.ctx.suppress_chars() = true; }, (Some(VirtualKeyCode::Escape), _) => { @@ -1143,6 +1158,8 @@ mod tests { fn pop_word_search(&mut self) {} + fn advance_search_origin(&mut self, _direction: Direction) {} + fn search_direction(&self) -> Direction { Direction::Right } -- cgit