Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions crates/agent_ui/src/conversation_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8620,6 +8620,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);
Expand Down
15 changes: 15 additions & 0 deletions crates/agent_ui/src/conversation_view/thread_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2117,6 +2117,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 methods

pub fn expand_message_editor(
Expand Down Expand Up @@ -3961,6 +3975,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))
Expand Down
Loading