From 19fc6737612fbfe41643f6f694a0123dc35bae24 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Fri, 6 Mar 2026 11:35:02 -0600 Subject: [PATCH] fixing eliding text panicing when using text that isn't UTF-8 --- src/ui/library.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/ui/library.rs b/src/ui/library.rs index c95008c..debfb8d 100644 --- a/src/ui/library.rs +++ b/src/ui/library.rs @@ -1513,10 +1513,25 @@ pub fn elide_text(text: impl AsRef, width: f32) -> String { if text_length > width { format!( "{}...", - text.split_at( + if let Some((first, _second)) = text.split_at_checked( ((width / CHAR_SIZE) - 3.0).floor() as usize - ) - .0 + ) { + first + } else if let Some((first, _second)) = text + .split_at_checked( + ((width / CHAR_SIZE) - 5.0).floor() as usize + ) + { + first + } else if let Some((first, _second)) = text + .split_at_checked( + ((width / CHAR_SIZE) - 7.0).floor() as usize + ) + { + first + } else { + &text + } ) } else { text