improv: show ellipsis if nothing else fits

If buffer is small enough that char+ellipsis doesn't fit, then show
ellipsis alone. If buffer is smaller than ellipsis, show nothing.
This commit is contained in:
Hojjat 2026-02-20 15:25:02 -07:00 committed by Jeremy Soller
parent d304a49536
commit a8873a0536
3 changed files with 31 additions and 0 deletions

View file

@ -1860,11 +1860,26 @@ impl ShapeLine {
current_visual_line.w = starting_line.w + ending_line.w + ellipsis_w;
current_visual_line.spaces = starting_line.spaces + ending_line.spaces;
}
None if forward_pass_overflowed && width > ellipsis_w => {
// buffer is small enough that the forward pass didn't fit
// only show the ellipsis
current_visual_line
.ranges
.push(self.ellipsis_vlrange(if self.rtl {
unicode_bidi::Level::rtl()
} else {
unicode_bidi::Level::ltr()
}));
current_visual_line.ellipsized = true;
current_visual_line.w = ellipsis_w;
current_visual_line.spaces = 0;
}
_ => {
// everything fit in the forward pass
current_visual_line.ranges = starting_line.ranges;
current_visual_line.w = starting_line.w;
current_visual_line.spaces = starting_line.spaces;
current_visual_line.ellipsized = false;
}
}
}

View file

@ -183,3 +183,16 @@ fn test_ellipsize_bidi_isolates_middle_bug() {
.canvas(220, 50)
.validate_text_rendering();
}
#[test]
fn test_ellipsize_ltr_middle_small_buffer() {
let attrs = Attrs::new().family(Family::Name("Inter"));
DrawTestCfg::new("ellipsize_ltr_middle_small_buffer")
.font_size(20., 26.)
.font_attrs(attrs)
.text("A/B Tester x8 Mono")
.wrap(Wrap::None)
.ellipsize(Ellipsize::Middle(EllipsizeHeightLimit::Lines(1)))
.canvas(30, 100)
.validate_text_rendering();
}

View file

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:4cfbb42f584b56040a99ddb82eebdecc967a89ce340d393aa651c2a441fd7fcf
size 764