Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

gpui: Fix truncation flickering (#45373)

Danilo Leal32600f255aea
diff --git a/crates/gpui/src/elements/text.rs b/crates/gpui/src/elements/text.rs
index 942a0a32652..770c1f87143 100644
--- a/crates/gpui/src/elements/text.rs
+++ b/crates/gpui/src/elements/text.rs
@@ -372,11 +372,17 @@ impl TextLayout {
(None, "".into(), TruncateFrom::End)
};
+ // Only use cached layout if:
+ // 1. We have a cached size
+ // 2. wrap_width matches (or both are None)
+ // 3. truncate_width is None (if truncate_width is Some, we need to re-layout
+ // because the previous layout may have been computed without truncation)
if let Some(text_layout) = element_state.0.borrow().as_ref()
- && text_layout.size.is_some()
+ && let Some(size) = text_layout.size
&& (wrap_width.is_none() || wrap_width == text_layout.wrap_width)
+ && truncate_width.is_none()
{
- return text_layout.size.unwrap();
+ return size;
}
let mut line_wrapper = cx.text_system().line_wrapper(text_style.font(), font_size);
diff --git a/crates/ui/src/components/label/label_like.rs b/crates/ui/src/components/label/label_like.rs
index f6e7a1b893d..03fde4083d5 100644
--- a/crates/ui/src/components/label/label_like.rs
+++ b/crates/ui/src/components/label/label_like.rs
@@ -241,10 +241,16 @@ impl RenderOnce for LabelLike {
.when(self.strikethrough, |this| this.line_through())
.when(self.single_line, |this| this.whitespace_nowrap())
.when(self.truncate, |this| {
- this.overflow_x_hidden().text_ellipsis()
+ this.min_w_0()
+ .overflow_x_hidden()
+ .whitespace_nowrap()
+ .text_ellipsis()
})
.when(self.truncate_start, |this| {
- this.overflow_x_hidden().text_ellipsis_start()
+ this.min_w_0()
+ .overflow_x_hidden()
+ .whitespace_nowrap()
+ .text_ellipsis_start()
})
.text_color(color)
.font_weight(