aboutsummaryrefslogtreecommitdiff
path: root/alacritty/src/input
diff options
context:
space:
mode:
authorChristian Duerr <contact@christianduerr.com>2025-05-20 23:53:03 +0000
committerGitHub <noreply@github.com>2025-05-20 23:53:03 +0000
commit71feeeeccc422d8092bda56b0d38693290f7585f (patch)
tree22fc0210063e9222e3c899faa81e1aaa2be00356 /alacritty/src/input
parent2bc1bb49e9c9a4861a2bc3eafcbaa652cda26ded (diff)
downloadr-alacritty-71feeeeccc422d8092bda56b0d38693290f7585f.tar.gz
r-alacritty-71feeeeccc422d8092bda56b0d38693290f7585f.tar.bz2
r-alacritty-71feeeeccc422d8092bda56b0d38693290f7585f.zip
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 <fletcher@gornick.dev>
Diffstat (limited to 'alacritty/src/input')
-rw-r--r--alacritty/src/input/mod.rs21
1 files changed, 21 insertions, 0 deletions
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<T: EventListener> {
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<T: EventListener> {
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<I, S>(&self, _program: &str, _args: I)
@@ -278,6 +280,21 @@ impl<T: EventListener> Execute<T> 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 {