From 13e57fa0b5df750dd68613f7558adf9964c38bf7 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Wed, 12 Oct 2022 09:23:21 -0700 Subject: [PATCH] fix wrapping issue with double-wide cells and hyperlink rules We weren't including the invisible space cells into the model as part of building up the logical line, resulting in the logical line being shorter than it should have been. That resulted in some of the components of the double wide cells not being rendered in the correct place. refs: https://github.com/wez/wezterm/issues/2571 refs: https://github.com/wez/wezterm/issues/2568 --- docs/changelog.md | 3 +++ termwiz/src/surface/line/line.rs | 3 +++ termwiz/src/surface/line/test.rs | 15 +++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/docs/changelog.md b/docs/changelog.md index 118b03803..1f2a74649 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -87,6 +87,9 @@ As features stabilize some brief notes about them will accumulate here. * Multiple active multiplexer client domain connections could result in showing duplicate tabs in a window [#2616](https://github.com/wez/wezterm/issues/2616) +* Incorrect line width when applying hyperlink rules to a wrapped line + containing double-wide cells. + [#2568](https://github.com/wez/wezterm/issues/2568) #### Changed * Removed Last Resort fallback font diff --git a/termwiz/src/surface/line/line.rs b/termwiz/src/surface/line/line.rs index 64c03bb1d..53a530edf 100644 --- a/termwiz/src/surface/line/line.rs +++ b/termwiz/src/surface/line/line.rs @@ -1097,6 +1097,9 @@ impl Line { CellStorage::V(cells) => { for cell in other.visible_cells() { cells.push(cell.as_cell()); + for _ in 1.. cell.width() { + cells.push(Cell::new(' ', cell.attrs().clone())); + } } } CellStorage::C(cl) => { diff --git a/termwiz/src/surface/line/test.rs b/termwiz/src/surface/line/test.rs index 8db036b47..fd0da5fe9 100644 --- a/termwiz/src/surface/line/test.rs +++ b/termwiz/src/surface/line/test.rs @@ -8,6 +8,21 @@ use crate::surface::SEQ_ZERO; use k9::assert_equal as assert_eq; use std::sync::Arc; +/// There are 4 double-wide graphemes that occupy 2 cells each. +/// When we join the lines, we must preserve the invisible blank +/// that is part of the grapheme otherwise our metrics will be +/// wrong. +/// +#[test] +fn append_line() { + let mut line1: Line = "0123456789".into(); + let line2: Line = "グループaa".into(); + + line1.append_line(line2, SEQ_ZERO); + + assert_eq!(line1.len(), 20); +} + #[test] fn hyperlinks() { let text = "❤ 😍🤢 http://example.com \u{1f468}\u{1f3fe}\u{200d}\u{1f9b0} http://example.com";