From 35fd69b0d5ae8d8e2d6e0f4e806b75ef7c5a7faf Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Tue, 15 Nov 2022 15:38:45 -0700 Subject: [PATCH] partially handling overflowing tab titles The recent changes to clustering make this more likely to happen. This doesn't handle overflow resulting from changing styles in the tab title, but those are less common. refs: https://github.com/wez/wezterm/issues/2560 --- wezterm-gui/src/termwindow/box_model.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/wezterm-gui/src/termwindow/box_model.rs b/wezterm-gui/src/termwindow/box_model.rs index 97aa98da2..d903facc8 100644 --- a/wezterm-gui/src/termwindow/box_model.rs +++ b/wezterm-gui/src/termwindow/box_model.rs @@ -267,9 +267,25 @@ impl Element { } pub fn with_line(font: &Rc, line: &Line, palette: &ColorPalette) -> Self { - let mut content = vec![]; + let mut content: Vec = vec![]; + let mut prior_attr = None; for cluster in line.cluster(None) { + // Clustering may introduce cluster boundaries when the text hasn't actually + // changed style. Undo that here. + // There's still an issue where the style does actually change and we + // subsequently don't clip the element. + // + if let Some(prior) = content.last_mut() { + let (fg, bg) = prior_attr.as_ref().unwrap(); + if cluster.attrs.background() == *bg && cluster.attrs.foreground() == *fg { + if let ElementContent::Text(t) = &mut prior.content { + t.push_str(&cluster.text); + continue; + } + } + } + let child = Element::new(font, ElementContent::Text(cluster.text)).colors(ElementColors { border: BorderColor::default(), @@ -292,6 +308,7 @@ impl Element { }); content.push(child); + prior_attr.replace((cluster.attrs.foreground(), cluster.attrs.background())); } Self::new(font, ElementContent::Children(content))