fixing eliding text panicing when using text that isn't UTF-8

This commit is contained in:
Chris Cochrun 2026-03-06 11:35:02 -06:00
parent 508d9a2d88
commit 19fc673761

View file

@ -1513,10 +1513,25 @@ pub fn elide_text(text: impl AsRef<str>, 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