diff options
author | Christian Duerr <contact@christianduerr.com> | 2023-10-20 11:33:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-20 13:33:38 +0400 |
commit | 845a5d8a8d47c233c4ed8177ecbb20b05b22118b (patch) | |
tree | 057f4c5974f60defa0c6f79060ef26e59398b1f1 /alacritty_terminal | |
parent | 7ceb638ff80eca99ac63df5fd8cbb2f703d4637a (diff) | |
download | alacritty-845a5d8a8d47c233c4ed8177ecbb20b05b22118b.tar.gz alacritty-845a5d8a8d47c233c4ed8177ecbb20b05b22118b.zip |
Add inline vi mode search
This patch adds inline search to vi mode using `f`/`F` and `t`/`T` as
default bindings. The behavior matches that of vim.
Fixes #7203.
Diffstat (limited to 'alacritty_terminal')
-rw-r--r-- | alacritty_terminal/src/term/search.rs | 50 |
1 files changed, 34 insertions, 16 deletions
diff --git a/alacritty_terminal/src/term/search.rs b/alacritty_terminal/src/term/search.rs index c10ef40d..8e329255 100644 --- a/alacritty_terminal/src/term/search.rs +++ b/alacritty_terminal/src/term/search.rs @@ -513,7 +513,25 @@ impl<T> Term<T> { } /// Find left end of semantic block. - pub fn semantic_search_left(&self, mut point: Point) -> Point { + #[must_use] + pub fn semantic_search_left(&self, point: Point) -> Point { + match self.inline_search_left(point, &self.semantic_escape_chars) { + Ok(point) => self.grid.iter_from(point).next().map_or(point, |cell| cell.point), + Err(point) => point, + } + } + + /// Find right end of semantic block. + #[must_use] + pub fn semantic_search_right(&self, point: Point) -> Point { + match self.inline_search_right(point, &self.semantic_escape_chars) { + Ok(point) => self.grid.iter_from(point).prev().map_or(point, |cell| cell.point), + Err(point) => point, + } + } + + /// Searching to the left, find the next character contained in `needles`. + pub fn inline_search_left(&self, mut point: Point, needles: &str) -> Result<Point, Point> { // Limit the starting point to the last line in the history point.line = max(point.line, self.topmost_line()); @@ -522,22 +540,22 @@ impl<T> Term<T> { let wide = Flags::WIDE_CHAR | Flags::WIDE_CHAR_SPACER | Flags::LEADING_WIDE_CHAR_SPACER; while let Some(cell) = iter.prev() { - if !cell.flags.intersects(wide) && self.semantic_escape_chars.contains(cell.c) { - break; - } + point = cell.point; - if cell.point.column == last_column && !cell.flags.contains(Flags::WRAPLINE) { - break; // cut off if on new line or hit escape char + if !cell.flags.intersects(wide) && needles.contains(cell.c) { + return Ok(point); } - point = cell.point; + if point.column == last_column && !cell.flags.contains(Flags::WRAPLINE) { + break; + } } - point + Err(point) } - /// Find right end of semantic block. - pub fn semantic_search_right(&self, mut point: Point) -> Point { + /// Searching to the right, find the next character contained in `needles`. + pub fn inline_search_right(&self, mut point: Point, needles: &str) -> Result<Point, Point> { // Limit the starting point to the last line in the history point.line = max(point.line, self.topmost_line()); @@ -545,18 +563,18 @@ impl<T> Term<T> { let last_column = self.columns() - 1; for cell in self.grid.iter_from(point) { - if !cell.flags.intersects(wide) && self.semantic_escape_chars.contains(cell.c) { - break; - } - point = cell.point; + if !cell.flags.intersects(wide) && needles.contains(cell.c) { + return Ok(point); + } + if point.column == last_column && !cell.flags.contains(Flags::WRAPLINE) { - break; // cut off if on new line or hit escape char + break; } } - point + Err(point) } /// Find the beginning of the current line across linewraps. |