summaryrefslogtreecommitdiffstats
path: root/alacritty_terminal
diff options
context:
space:
mode:
authora5ob7r <12132068+a5ob7r@users.noreply.github.com>2021-06-21 03:01:47 +0900
committerGitHub <noreply@github.com>2021-06-20 18:01:47 +0000
commitfa2fa39804fd0e170d0293b442390ae189503856 (patch)
tree74dae4ca93a6aa1ddee7330423c74312b462c9d3 /alacritty_terminal
parent7e4325796d6a5179873dac1b72e3286cc68aa85a (diff)
Fix regex search regression
Diffstat (limited to 'alacritty_terminal')
-rw-r--r--alacritty_terminal/src/term/search.rs41
1 files changed, 33 insertions, 8 deletions
diff --git a/alacritty_terminal/src/term/search.rs b/alacritty_terminal/src/term/search.rs
index fd90f0e1..bf7f43d1 100644
--- a/alacritty_terminal/src/term/search.rs
+++ b/alacritty_terminal/src/term/search.rs
@@ -239,12 +239,7 @@ impl<T> Term<T> {
}
// Stop once we've reached the target point.
- //
- // We check beyond the point itself to account for skipped characters after wide chars
- // without spacer.
- if (direction == Direction::Right && point >= end)
- || (direction == Direction::Left && point <= end)
- {
+ if point == end {
break;
}
@@ -289,9 +284,14 @@ impl<T> Term<T> {
direction: Direction,
) {
match direction {
- Direction::Right if cell.flags.contains(Flags::WIDE_CHAR) => {
+ // In the alternate screen buffer there might not be a wide char spacer after a wide
+ // char, so we only advance the iterator when the wide char is not in the last column.
+ Direction::Right
+ if cell.flags.contains(Flags::WIDE_CHAR)
+ && iter.point().column < self.last_column() =>
+ {
iter.next();
- },
+ }
Direction::Right if cell.flags.contains(Flags::LEADING_WIDE_CHAR_SPACER) => {
if let Some(Indexed { cell: new_cell, .. }) = iter.next() {
*cell = new_cell;
@@ -798,4 +798,29 @@ mod tests {
let mut iter = RegexIter::new(start, end, Direction::Right, &term, &dfas);
assert_eq!(iter.next(), None);
}
+
+ #[test]
+ fn wrap_around_to_another_end() {
+ #[rustfmt::skip]
+ let term = mock_term("\
+ abc\r\n\
+ def\
+ ");
+
+ // Bottom to top.
+ let dfas = RegexSearch::new("abc").unwrap();
+ let start = Point::new(Line(1), Column(0));
+ let end = Point::new(Line(0), Column(2));
+ let match_start = Point::new(Line(0), Column(0));
+ let match_end = Point::new(Line(0), Column(2));
+ assert_eq!(term.regex_search_right(&dfas, start, end), Some(match_start..=match_end));
+
+ // Top to bottom.
+ let dfas = RegexSearch::new("def").unwrap();
+ let start = Point::new(Line(0), Column(2));
+ let end = Point::new(Line(1), Column(0));
+ let match_start = Point::new(Line(1), Column(0));
+ let match_end = Point::new(Line(1), Column(2));
+ assert_eq!(term.regex_search_left(&dfas, start, end), Some(match_start..=match_end));
+ }
}