Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
agent: Cancel pending in-edit user message upon new message submit (#29565)
Danilo Lealbbe8d6a65412
diff --git a/crates/agent/src/active_thread.rs b/crates/agent/src/active_thread.rsindex 2b60d976971..e8e5351c1aa 100644--- a/crates/agent/src/active_thread.rs+++ b/crates/agent/src/active_thread.rs@@ -903,6 +903,11 @@ impl ActiveThread {cx: &mut Context<Self>,) {match event {+ ThreadEvent::CancelEditing => {+ if self.editing_message.is_some() {+ self.cancel_editing_message(&menu::Cancel, window, cx);+ }+ }ThreadEvent::ShowError(error) => {self.last_error = Some(error.clone());}diff --git a/crates/agent/src/message_editor.rs b/crates/agent/src/message_editor.rsindex 17fbcfb5a0b..65ae2db0b57 100644--- a/crates/agent/src/message_editor.rs+++ b/crates/agent/src/message_editor.rs@@ -244,6 +244,10 @@ impl MessageEditor {return;}+ self.thread.update(cx, |thread, cx| {+ thread.cancel_editing(cx);+ });+if self.thread.read(cx).is_generating() {self.stop_current_and_send_new_message(window, cx);return;@@ -312,6 +316,10 @@ impl MessageEditor {}fn stop_current_and_send_new_message(&mut self, window: &mut Window, cx: &mut Context<Self>) {+ self.thread.update(cx, |thread, cx| {+ thread.cancel_editing(cx);+ });+let cancelled = self.thread.update(cx, |thread, cx| {thread.cancel_last_completion(Some(window.window_handle()), cx)});diff --git a/crates/agent/src/thread.rs b/crates/agent/src/thread.rsindex 88a56bf2a5b..a723d082c1f 100644--- a/crates/agent/src/thread.rs+++ b/crates/agent/src/thread.rs@@ -1866,6 +1866,14 @@ impl Thread {canceled}+ /// Signals that any in-progress editing should be canceled.+ ///+ /// This method is used to notify listeners (like ActiveThread) that+ /// they should cancel any editing operations.+ pub fn cancel_editing(&mut self, cx: &mut Context<Self>) {+ cx.emit(ThreadEvent::CancelEditing);+ }+pub fn feedback(&self) -> Option<ThreadFeedback> {self.feedback}@@ -2384,6 +2392,7 @@ pub enum ThreadEvent {},CheckpointChanged,ToolConfirmationNeeded,+ CancelEditing,}impl EventEmitter<ThreadEvent> for Thread {}diff --git a/crates/eval/src/example.rs b/crates/eval/src/example.rsindex c0c3c4cd99f..9a9b7fd577f 100644--- a/crates/eval/src/example.rs+++ b/crates/eval/src/example.rs@@ -276,7 +276,8 @@ impl ExampleContext {| ThreadEvent::ReceivedTextChunk| ThreadEvent::StreamedToolUse { .. }| ThreadEvent::CheckpointChanged- | ThreadEvent::UsageUpdated(_) => {+ | ThreadEvent::UsageUpdated(_)+ | ThreadEvent::CancelEditing => {tx.try_send(Ok(())).ok();if std::env::var("ZED_EVAL_DEBUG").is_ok() {println!("{}Event: {:#?}", log_prefix, event);