From 113f0780b37481c782f84506df7efa055efd5fd0 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Thu, 6 Nov 2025 08:58:20 +0100 Subject: [PATCH] agent_ui: Fix string slicing panic in message editor (#42068) Fixes ZED-302 Release Notes: - Fixed a panic in agent message editor when using multibyte whitespace characters --- crates/agent_ui/src/acp/message_editor.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/agent_ui/src/acp/message_editor.rs b/crates/agent_ui/src/acp/message_editor.rs index 856cc4d0d47d1e1d618c0056c771dfabe3c0bda4..04fe4b2bfdac736fbfba7abecf68b2391d9b8192 100644 --- a/crates/agent_ui/src/acp/message_editor.rs +++ b/crates/agent_ui/src/acp/message_editor.rs @@ -717,7 +717,10 @@ impl MessageEditor { let mut all_tracked_buffers = Vec::new(); let result = editor.update(cx, |editor, cx| { - let mut ix = text.chars().position(|c| !c.is_whitespace()).unwrap_or(0); + let (mut ix, _) = text + .char_indices() + .find(|(_, c)| !c.is_whitespace()) + .unwrap_or((0, '\0')); let mut chunks: Vec = Vec::new(); let text = editor.text(cx); editor.display_map.update(cx, |map, cx| { @@ -2879,7 +2882,7 @@ mod tests { cx.run_until_parked(); editor.update_in(cx, |editor, window, cx| { - editor.set_text(" hello world ", window, cx); + editor.set_text(" \u{A0}してhello world ", window, cx); }); let (content, _) = message_editor @@ -2890,7 +2893,7 @@ mod tests { assert_eq!( content, vec![acp::ContentBlock::Text(acp::TextContent { - text: "hello world".into(), + text: "してhello world".into(), annotations: None, meta: None })]