From fa2fa39804fd0e170d0293b442390ae189503856 Mon Sep 17 00:00:00 2001 From: a5ob7r <12132068+a5ob7r@users.noreply.github.com> Date: Mon, 21 Jun 2021 03:01:47 +0900 Subject: Fix regex search regression --- alacritty_terminal/src/term/search.rs | 41 ++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 8 deletions(-) (limited to 'alacritty_terminal') 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 Term { } // 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 Term { 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)); + } } -- cgit v1.2.3