diff options
author | Christian Duerr <contact@christianduerr.com> | 2020-07-15 21:27:32 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-15 21:27:32 +0000 |
commit | 142f84efb955a9fa59f4205ec3a6db3964c5f433 (patch) | |
tree | 450d1f210dd961de872f8105cdb4290a13194d97 /alacritty/src/input.rs | |
parent | d868848ef162ce1d2d5e41b690a592199e9f652d (diff) | |
download | r-alacritty-142f84efb955a9fa59f4205ec3a6db3964c5f433.tar.gz r-alacritty-142f84efb955a9fa59f4205ec3a6db3964c5f433.tar.bz2 r-alacritty-142f84efb955a9fa59f4205ec3a6db3964c5f433.zip |
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.
Diffstat (limited to 'alacritty/src/input.rs')
-rw-r--r-- | alacritty/src/input.rs | 25 |
1 files changed, 21 insertions, 4 deletions
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<T: EventListener> { 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<T: EventListener> Execute<T> 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<T>> Processor<'a, T, A> { #[inline] pub fn mouse_moved(&mut self, position: PhysicalPosition<f64>) { + 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<T>> 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<T>> 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 } |