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: Scroll to bottom after submitting a new message (#32819)

Danilo Leal69e84c0c48ab
diff --git a/crates/agent/src/agent_panel.rs b/crates/agent/src/agent_panel.rs
index d00c9791943..7d79ab22027 100644
--- a/crates/agent/src/agent_panel.rs
+++ b/crates/agent/src/agent_panel.rs
@@ -520,10 +520,15 @@ impl AgentPanel {
});
let message_editor_subscription =
- cx.subscribe(&message_editor, |_, _, event, cx| match event {
+ cx.subscribe(&message_editor, |this, _, event, cx| match event {
MessageEditorEvent::Changed | MessageEditorEvent::EstimatedTokenCount => {
cx.notify();
}
+ MessageEditorEvent::ScrollThreadToBottom => {
+ this.thread.update(cx, |thread, cx| {
+ thread.scroll_to_bottom(cx);
+ });
+ }
});
let thread_id = thread.read(cx).id().clone();
@@ -803,10 +808,15 @@ impl AgentPanel {
self.message_editor.focus_handle(cx).focus(window);
let message_editor_subscription =
- cx.subscribe(&self.message_editor, |_, _, event, cx| match event {
+ cx.subscribe(&self.message_editor, |this, _, event, cx| match event {
MessageEditorEvent::Changed | MessageEditorEvent::EstimatedTokenCount => {
cx.notify();
}
+ MessageEditorEvent::ScrollThreadToBottom => {
+ this.thread.update(cx, |thread, cx| {
+ thread.scroll_to_bottom(cx);
+ });
+ }
});
self._active_thread_subscriptions = vec![
@@ -1018,10 +1028,15 @@ impl AgentPanel {
self.message_editor.focus_handle(cx).focus(window);
let message_editor_subscription =
- cx.subscribe(&self.message_editor, |_, _, event, cx| match event {
+ cx.subscribe(&self.message_editor, |this, _, event, cx| match event {
MessageEditorEvent::Changed | MessageEditorEvent::EstimatedTokenCount => {
cx.notify();
}
+ MessageEditorEvent::ScrollThreadToBottom => {
+ this.thread.update(cx, |thread, cx| {
+ thread.scroll_to_bottom(cx);
+ });
+ }
});
self._active_thread_subscriptions = vec![
diff --git a/crates/agent/src/message_editor.rs b/crates/agent/src/message_editor.rs
index ee7ebd30924..288b2b650bf 100644
--- a/crates/agent/src/message_editor.rs
+++ b/crates/agent/src/message_editor.rs
@@ -301,6 +301,7 @@ impl MessageEditor {
self.set_editor_is_expanded(false, cx);
self.send_to_model(window, cx);
+ cx.emit(MessageEditorEvent::ScrollThreadToBottom);
cx.notify();
}
@@ -906,7 +907,7 @@ impl MessageEditor {
)
}
- fn render_changed_buffers(
+ fn render_edits_bar(
&self,
changed_buffers: &BTreeMap<Entity<Buffer>, Entity<BufferDiff>>,
window: &mut Window,
@@ -1510,6 +1511,7 @@ impl EventEmitter<MessageEditorEvent> for MessageEditor {}
pub enum MessageEditorEvent {
EstimatedTokenCount,
Changed,
+ ScrollThreadToBottom,
}
impl Focusable for MessageEditor {
@@ -1537,7 +1539,7 @@ impl Render for MessageEditor {
v_flex()
.size_full()
.when(changed_buffers.len() > 0, |parent| {
- parent.child(self.render_changed_buffers(&changed_buffers, window, cx))
+ parent.child(self.render_edits_bar(&changed_buffers, window, cx))
})
.child(self.render_editor(window, cx))
.children({