Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
agent_ui: Fix string slicing panic in message editor (#42068)
Lukas Wirth113f0780b374
diff --git a/crates/agent_ui/src/acp/message_editor.rs b/crates/agent_ui/src/acp/message_editor.rsindex 856cc4d0d47..04fe4b2bfda 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<acp::ContentBlock> = 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})]