diff --git a/CHANGELOG.md b/CHANGELOG.md index d2e84ce..8c779de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,13 @@ reads that marker. ### Fixed +- An empty regex match at the end of a row is reported one past the + last cell the text covers, by one rule for every row, as `find` reports + a match after a wide character: on six columns `find_all_matches($)` + gave `(0, 5, "")` on `abcdef`, the column of `f`, and `(2, 5, "")` on + `abcd中`, the second column of `中`, where `ab` gave `(1, 2, "")`. It + now gives `(0, 6, "")` and `(2, 6, "")`. A test that expected the last + cell's column for such a match should expect the column after it. (#853) - The HTML rendering stops a blinking run under `prefers-reduced-motion`. The run's `animation` is in its own `style` attribute, which outranks every normal declaration from a style sheet, so the `animation:none` diff --git a/crates/termlens/src/screen.rs b/crates/termlens/src/screen.rs index 9bed282..5fcb669 100644 --- a/crates/termlens/src/screen.rs +++ b/crates/termlens/src/screen.rs @@ -2420,9 +2420,10 @@ impl Screen { cols.resize(text.len(), col); debug_assert!(text.len() > before || cell.is_wide_continuation()); } - // One extra entry, so a match at the very end of the row maps to - // the last column instead of falling off the map. - cols.push(self.cols.saturating_sub(1)); + // One extra entry, so an empty match at the very end of the row maps + // to the column a character printed next would start at, one past + // the last cell the text covers, instead of falling off the map. + cols.push(self.cols); (text, cols) } diff --git a/crates/termlens/tests/search.rs b/crates/termlens/tests/search.rs index 687805e..8d9afa4 100644 --- a/crates/termlens/tests/search.rs +++ b/crates/termlens/tests/search.rs @@ -302,6 +302,26 @@ mod patterns { use super::*; use regex::Regex; + #[test] + fn an_empty_match_at_the_end_of_a_row_is_one_past_its_last_cell() -> termlens::Result<()> { + // Six columns: a full row, a short row, a full row ending in a wide + // character. An empty match at a row's end is reported by one rule, + // the column a character printed next would start at, and never as + // the second column of a wide character (#853). + let s = Screen::parse("size: 6x3 cursor: 0,0\nabcdef\nab\nabcd中")?; + let end = Regex::new("$").unwrap(); + assert_eq!( + s.find_all_matches(&end), + [ + (0, 6, String::new()), + (1, 2, String::new()), + (2, 6, String::new()) + ], + "{s}" + ); + Ok(()) + } + #[test] fn a_pattern_matches_within_a_row_and_reports_cell_columns() -> termlens::Result<()> { let mut t = emit(&["--raw", r"汉 myapp v1.42.0 ready\nbuild 7\nDONE", "--wait"])?;