Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Allow editing queued message by pressing up in an empty editor (#58807)
Lukas Wirth67427ffbc60a
diff --git a/crates/agent_ui/src/conversation_view.rs b/crates/agent_ui/src/conversation_view.rsindex 5d91c1c24d2..bf923b98d67 100644--- a/crates/agent_ui/src/conversation_view.rs+++ b/crates/agent_ui/src/conversation_view.rs@@ -8810,6 +8810,65 @@ pub(crate) mod tests {);}+ #[gpui::test]+ async fn test_move_up_in_empty_editor_restores_last_queued_message(cx: &mut TestAppContext) {+ init_test(cx);++ let (conversation_view, cx) =+ setup_conversation_view(StubAgentServer::default_response(), cx).await;+ add_to_workspace(conversation_view.clone(), cx);++ active_thread(&conversation_view, cx).update(cx, |thread, cx| {+ thread.add_to_queue(+ vec![acp::ContentBlock::Text(acp::TextContent::new(+ "first queued".to_string(),+ ))],+ vec![],+ cx,+ );+ thread.add_to_queue(+ vec![acp::ContentBlock::Text(acp::TextContent::new(+ "second queued".to_string(),+ ))],+ vec![],+ cx,+ );+ });+ cx.run_until_parked();++ let editor = message_editor(&conversation_view, cx);+ cx.focus(&editor);++ editor.update_in(cx, |_editor, window, cx| {+ window.dispatch_action(Box::new(zed_actions::editor::MoveUp), cx);+ });+ cx.run_until_parked();++ let queue_len = active_thread(&conversation_view, cx)+ .read_with(cx, |thread, _cx| thread.local_queued_messages.len());+ assert_eq!(+ queue_len, 1,+ "Up arrow should pull the last queued message out of the queue"+ );+ let text = editor.update(cx, |editor, cx| editor.text(cx));+ assert_eq!(+ text, "second queued",+ "Main editor should contain the last queued message"+ );++ // With a non-empty editor, another MoveUp must not consume the queue.+ editor.update_in(cx, |_editor, window, cx| {+ window.dispatch_action(Box::new(zed_actions::editor::MoveUp), cx);+ });+ cx.run_until_parked();++ let queue_len = active_thread(&conversation_view, cx)+ .read_with(cx, |thread, _cx| thread.local_queued_messages.len());+ assert_eq!(queue_len, 1, "Queue should be untouched");+ let text = editor.update(cx, |editor, cx| editor.text(cx));+ assert_eq!(text, "second queued");+ }+#[gpui::test]async fn test_paste_text_into_queued_message_promotes_to_main_editor(cx: &mut TestAppContext) {init_test(cx);diff --git a/crates/agent_ui/src/conversation_view/thread_view.rs b/crates/agent_ui/src/conversation_view/thread_view.rsindex 59ca41d9a60..6c4dc654621 100644--- a/crates/agent_ui/src/conversation_view/thread_view.rs+++ b/crates/agent_ui/src/conversation_view/thread_view.rs@@ -2164,6 +2164,20 @@ impl ThreadView {true}+ fn handle_message_editor_move_up(+ &mut self,+ _: &zed_actions::editor::MoveUp,+ window: &mut Window,+ cx: &mut Context<Self>,+ ) {+ if !self.message_editor.read(cx).is_empty(cx) || self.local_queued_messages.is_empty() {+ cx.propagate();+ return;+ }+ let last_index = self.local_queued_messages.len() - 1;+ self.move_queued_message_to_main_editor(last_index, None, None, window, cx);+ }+// editor methodspub fn expand_message_editor(@@ -4039,6 +4053,7 @@ impl ThreadView {.p_2().bg(editor_bg_color).justify_center()+ .on_action(cx.listener(Self::handle_message_editor_move_up)).map(|this| {if has_messages {this.on_action(cx.listener(Self::expand_message_editor))