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.

ui: Fix LoadingLabel animation panic on CJK/emoji text (#45632)

MomentDerek4efe93cfbfd0
diff --git a/crates/ui/src/components/label/loading_label.rs b/crates/ui/src/components/label/loading_label.rs
index 0b6b027e477..c3e18fa969f 100644
--- a/crates/ui/src/components/label/loading_label.rs
+++ b/crates/ui/src/components/label/loading_label.rs
@@ -93,14 +93,15 @@ impl RenderOnce for LoadingLabel {
move |mut label, animation_ix, delta| {
match animation_ix {
0 => {
- let chars_to_show = (delta * text.len() as f32).ceil() as usize;
- let text = SharedString::from(text[0..chars_to_show].to_string());
- label.set_text(text);
+ let byte_end =
+ text.floor_char_boundary((delta * text.len() as f32).ceil() as usize);
+ let visible_text = SharedString::new(&text[0..byte_end]);
+ label.set_text(visible_text);
}
1 => match delta {
- d if d < 0.25 => label.set_text(text.clone()),
- d if d < 0.5 => label.set_text(format!("{}.", text)),
- d if d < 0.75 => label.set_text(format!("{}..", text)),
+ ..0.25 => label.set_text(text.clone()),
+ ..0.5 => label.set_text(format!("{}.", text)),
+ ..0.75 => label.set_text(format!("{}..", text)),
_ => label.set_text(format!("{}...", text)),
},
_ => {}