From 71feeeeccc422d8092bda56b0d38693290f7585f Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Tue, 20 May 2025 23:53:03 +0000 Subject: Add * # { } vi motions This patch adds Vi's semantic search and paragraph motion. The semantic search uses either the selection or the semantic word under the cursor and jumps to the next match in the desired direction. Paragraph motion jumps to just above or below the current paragraph. Closes #7961. Co-authored-by: Fletcher Gornick --- alacritty/src/input/mod.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'alacritty/src/input') diff --git a/alacritty/src/input/mod.rs b/alacritty/src/input/mod.rs index 3f85512f..a69d2989 100644 --- a/alacritty/src/input/mod.rs +++ b/alacritty/src/input/mod.rs @@ -112,6 +112,7 @@ pub trait ActionContext { fn clipboard_mut(&mut self) -> &mut Clipboard; fn scheduler_mut(&mut self) -> &mut Scheduler; fn start_search(&mut self, _direction: Direction) {} + fn start_seeded_search(&mut self, _direction: Direction, _text: String) {} fn confirm_search(&mut self) {} fn cancel_search(&mut self) {} fn search_input(&mut self, _c: char) {} @@ -132,6 +133,7 @@ pub trait ActionContext { fn hint_input(&mut self, _character: char) {} fn trigger_hint(&mut self, _hint: &HintMatch) {} fn expand_selection(&mut self) {} + fn semantic_word(&self, point: Point) -> String; fn on_terminal_input_start(&mut self) {} fn paste(&mut self, _text: &str, _bracketed: bool) {} fn spawn_daemon(&self, _program: &str, _args: I) @@ -278,6 +280,21 @@ impl Execute for Action { }, Action::Vi(ViAction::InlineSearchNext) => ctx.inline_search_next(), Action::Vi(ViAction::InlineSearchPrevious) => ctx.inline_search_previous(), + Action::Vi(ViAction::SemanticSearchForward | ViAction::SemanticSearchBackward) => { + let seed_text = match ctx.terminal().selection_to_string() { + Some(selection) if !selection.is_empty() => selection, + // Get semantic word at the vi cursor position. + _ => ctx.semantic_word(ctx.terminal().vi_mode_cursor.point), + }; + + if !seed_text.is_empty() { + let direction = match self { + Action::Vi(ViAction::SemanticSearchForward) => Direction::Right, + _ => Direction::Left, + }; + ctx.start_seeded_search(direction, seed_text); + } + }, action @ Action::Search(_) if !ctx.search_active() => { debug!("Ignoring {action:?}: Search mode inactive"); }, @@ -1237,6 +1254,10 @@ mod tests { fn scheduler_mut(&mut self) -> &mut Scheduler { unimplemented!(); } + + fn semantic_word(&self, _point: Point) -> String { + unimplemented!(); + } } macro_rules! test_clickstate { -- cgit