Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
7 changes: 4 additions & 3 deletions crates/termlens/src/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
20 changes: 20 additions & 0 deletions crates/termlens/tests/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"])?;
Expand Down
Loading