Skip to content

armgit / zed

Public Imported from GitHub
0

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 panic in message editor (#44493)

Bennet Bo Fennerbfab0b71e0a9
diff --git a/crates/agent_ui/src/acp/message_editor.rs b/crates/agent_ui/src/acp/message_editor.rs
index a0aca0c51bd..bc293c98a84 100644
--- a/crates/agent_ui/src/acp/message_editor.rs
+++ b/crates/agent_ui/src/acp/message_editor.rs
@@ -567,6 +567,14 @@ impl MessageEditor {
{
cx.stop_propagation();
+ let insertion_target = self
+ .editor
+ .read(cx)
+ .selections
+ .newest_anchor()
+ .start
+ .text_anchor;
+
let project = workspace.read(cx).project().clone();
for selection in selections {
if let (Some(file_path), Some(line_range)) =
@@ -587,8 +595,7 @@ impl MessageEditor {
let snapshot = buffer.snapshot(cx);
let (excerpt_id, _, buffer_snapshot) =
snapshot.as_singleton().unwrap();
- let start_offset = buffer_snapshot.len();
- let text_anchor = buffer_snapshot.anchor_before(start_offset);
+ let text_anchor = insertion_target.bias_left(&buffer_snapshot);
editor.insert(&mention_text, window, cx);
editor.insert(" ", window, cx);