From 300099da2471bee6af66b3d32d97fc9f46f9a660 Mon Sep 17 00:00:00 2001 From: "zed-zippy[bot]" <234243425+zed-zippy[bot]@users.noreply.github.com> Date: Thu, 15 Jan 2026 16:17:06 +0000 Subject: [PATCH] gpui: Fix utf8 slicing panic in `truncate_line` (#46914) (cherry-pick to stable) (#46917) Cherry-pick of #46914 to stable ---- Fixes https://github.com/zed-industries/zed/issues/46904 Release Notes: - Fixed a panic in the git panel when utf8 multibyte character filenames got truncated Co-authored-by: Lukas Wirth --- crates/gpui/src/text_system/line_wrapper.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/crates/gpui/src/text_system/line_wrapper.rs b/crates/gpui/src/text_system/line_wrapper.rs index 457316f353a48fa112de1736b2b7eaa2d4c72313..48daee6fa12ac792b66ca749347c1aa1e8f37b3c 100644 --- a/crates/gpui/src/text_system/line_wrapper.rs +++ b/crates/gpui/src/text_system/line_wrapper.rs @@ -201,9 +201,10 @@ impl LineWrapper { self.should_truncate_line(&line, truncate_width, truncation_affix, truncate_from) { let result = match truncate_from { - TruncateFrom::Start => { - SharedString::from(format!("{truncation_affix}{}", &line[truncate_ix + 1..])) - } + TruncateFrom::Start => SharedString::from(format!( + "{truncation_affix}{}", + &line[line.ceil_char_boundary(truncate_ix + 1)..] + )), TruncateFrom::End => { SharedString::from(format!("{}{truncation_affix}", &line[..truncate_ix])) } @@ -600,12 +601,19 @@ mod tests { "aa bbb cccc dddd......", "......", ); + perform_test( + &mut wrapper, + "aa bbb cccc 🦀🦀🦀🦀🦀 eeee ffff gggg", + "aa bbb cccc 🦀🦀🦀🦀…", + "…", + ); } #[test] fn test_truncate_line_start() { let mut wrapper = build_wrapper(); + #[track_caller] fn perform_test( wrapper: &mut LineWrapper, text: &'static str, @@ -643,6 +651,12 @@ mod tests { "......dddd eeee fff gg", "......", ); + perform_test( + &mut wrapper, + "aaaa bbbb cccc 🦀🦀🦀🦀🦀 eeee fff gg", + "…🦀🦀🦀🦀 eeee fff gg", + "…", + ); } #[test]