agent_ui: Add check to prevent sending empty messages in MessageEditor (#36545)
Release Notes: - N/A
This commit is contained in:
parent
ceec258bf3
commit
d273aca1c1
2 changed files with 30 additions and 1 deletions
|
@ -66,7 +66,7 @@ pub struct MessageEditor {
|
||||||
_parse_slash_command_task: Task<()>,
|
_parse_slash_command_task: Task<()>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub enum MessageEditorEvent {
|
pub enum MessageEditorEvent {
|
||||||
Send,
|
Send,
|
||||||
Cancel,
|
Cancel,
|
||||||
|
@ -728,6 +728,9 @@ impl MessageEditor {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send(&mut self, _: &Chat, _: &mut Window, cx: &mut Context<Self>) {
|
fn send(&mut self, _: &Chat, _: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
if self.is_empty(cx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
cx.emit(MessageEditorEvent::Send)
|
cx.emit(MessageEditorEvent::Send)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4564,6 +4564,32 @@ pub(crate) mod tests {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[gpui::test]
|
||||||
|
async fn test_message_doesnt_send_if_empty(cx: &mut TestAppContext) {
|
||||||
|
init_test(cx);
|
||||||
|
|
||||||
|
let connection = StubAgentConnection::new();
|
||||||
|
|
||||||
|
let (thread_view, cx) = setup_thread_view(StubAgentServer::new(connection), cx).await;
|
||||||
|
add_to_workspace(thread_view.clone(), cx);
|
||||||
|
|
||||||
|
let message_editor = cx.read(|cx| thread_view.read(cx).message_editor.clone());
|
||||||
|
let mut events = cx.events(&message_editor);
|
||||||
|
message_editor.update_in(cx, |editor, window, cx| {
|
||||||
|
editor.set_text("", window, cx);
|
||||||
|
});
|
||||||
|
|
||||||
|
message_editor.update_in(cx, |_editor, window, cx| {
|
||||||
|
window.dispatch_action(Box::new(Chat), cx);
|
||||||
|
});
|
||||||
|
cx.run_until_parked();
|
||||||
|
// We shouldn't have received any messages
|
||||||
|
assert!(matches!(
|
||||||
|
events.try_next(),
|
||||||
|
Err(futures::channel::mpsc::TryRecvError { .. })
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_message_editing_regenerate(cx: &mut TestAppContext) {
|
async fn test_message_editing_regenerate(cx: &mut TestAppContext) {
|
||||||
init_test(cx);
|
init_test(cx);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue