From cde8fe0e85d4b5174eb807a313a94ef0e53fe8a4 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Thu, 23 Dec 2021 12:13:38 -0700 Subject: [PATCH] term: don't force zero-width graphemes into cells This isn't ideal, as we're discarding information, but in #1422 where the problem codepoint is a unicode bidi control, we can't and don't use that information anyway. We'll need to figure out how to incorporate that when we get to it. For now, this makes the presentation work correctly. refs: #1422 --- term/src/terminalstate/performer.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/term/src/terminalstate/performer.rs b/term/src/terminalstate/performer.rs index 3fe46e5a2..a3e834227 100644 --- a/term/src/terminalstate/performer.rs +++ b/term/src/terminalstate/performer.rs @@ -109,6 +109,16 @@ impl<'a> Performer<'a> { g }; + let print_width = grapheme_column_width(g, Some(self.unicode_version)); + if print_width == 0 { + // We got a zero-width grapheme. + // We used to force them into a cell to guarantee that we + // preserved them in the model, but it introduces presentation + // problems, such as + log::trace!("Eliding zero-width grapheme {:?}", g); + continue; + } + if self.wrap_next { // Since we're implicitly moving the cursor to the next // line, we need to tag the current position as wrapped @@ -130,12 +140,7 @@ impl<'a> Performer<'a> { let width = self.left_and_right_margins.end; let pen = self.pen.clone(); - // the max(1) here is to ensure that we advance to the next cell - // position for zero-width graphemes. We want to make sure that - // they occupy a cell so that we can re-emit them when we output them. - // If we didn't do this, then we'd effectively filter them out from - // the model, which seems like a lossy design choice. - let print_width = grapheme_column_width(g, Some(self.unicode_version)).max(1); + let wrappable = x + print_width >= width; let cell = Cell::new_grapheme_with_width(g, print_width, pen);