From 9458550c777c54f30ef70954cbcbf774989cc39c Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Sun, 14 Jan 2024 16:07:40 +0100 Subject: [PATCH] Fix inline search expanding across newlines Closes #7587. --- CHANGELOG.md | 6 +++++ alacritty_terminal/src/term/search.rs | 34 +++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a0e06c8..e34d9e0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ The sections should follow the order `Packaging`, `Added`, `Changed`, `Fixed` an The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## 0.13.2-dev + +### Fixed + +- Vi inline search/semantic selection expanding across newlines + ## 0.13.1 ### Added diff --git a/alacritty_terminal/src/term/search.rs b/alacritty_terminal/src/term/search.rs index 9e900b8a..585e191c 100644 --- a/alacritty_terminal/src/term/search.rs +++ b/alacritty_terminal/src/term/search.rs @@ -540,15 +540,15 @@ impl Term { let wide = Flags::WIDE_CHAR | Flags::WIDE_CHAR_SPACER | Flags::LEADING_WIDE_CHAR_SPACER; while let Some(cell) = iter.prev() { + if cell.point.column == last_column && !cell.flags.contains(Flags::WRAPLINE) { + 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; - } } Err(point) @@ -562,6 +562,11 @@ impl Term { let wide = Flags::WIDE_CHAR | Flags::WIDE_CHAR_SPACER | Flags::LEADING_WIDE_CHAR_SPACER; let last_column = self.columns() - 1; + // Immediately stop if start point in on line break. + if point.column == last_column && !self.grid[point].flags.contains(Flags::WRAPLINE) { + return Err(point); + } + for cell in self.grid.iter_from(point) { point = cell.point; @@ -1129,4 +1134,25 @@ mod tests { let end = Point::new(Line(0), Column(3)); assert_eq!(term.regex_search_right(&mut regex, start, end), Some(start..=end)); } + + #[test] + fn newline_breaking_semantic() { + #[rustfmt::skip] + let term = mock_term("\ + test abc\r\n\ + def test\ + "); + + // Start at last character. + let start = term.semantic_search_left(Point::new(Line(0), Column(7))); + let end = term.semantic_search_right(Point::new(Line(0), Column(7))); + assert_eq!(start, Point::new(Line(0), Column(5))); + assert_eq!(end, Point::new(Line(0), Column(7))); + + // Start at first character. + let start = term.semantic_search_left(Point::new(Line(1), Column(0))); + let end = term.semantic_search_right(Point::new(Line(1), Column(0))); + assert_eq!(start, Point::new(Line(1), Column(0))); + assert_eq!(end, Point::new(Line(1), Column(2))); + } }