From 72184933bd9a29d7cdca3874e378795c12e0abd4 Mon Sep 17 00:00:00 2001 From: dino Date: Mon, 27 Oct 2025 12:22:18 +0000 Subject: [PATCH] chore: tentative fix Remove the changes introduced in the previous commit and update the `MessageEditor.confirm_mention_for_selection` method in order to request autoscroll from the editor twice, one of them delayed, as this appears to fix the scrolling issue, regardless of the number of cursors used. I'm not yet entirely sure why this is the case, so further investigation is probably warranted in order to actually understand if this is the best fix we can do right now, and why. --- crates/agent_ui/src/acp/message_editor.rs | 19 +++++++++++++++++++ crates/editor/src/display_map.rs | 9 --------- crates/editor/src/display_map/fold_map.rs | 11 ++++------- crates/editor/src/scroll/autoscroll.rs | 2 +- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/crates/agent_ui/src/acp/message_editor.rs b/crates/agent_ui/src/acp/message_editor.rs index 34905ae591e60fef43e7f214470d7bfdcb01fdce..6cfa825b3ebd3e13c01f2bae4abfbf275b71b0f9 100644 --- a/crates/agent_ui/src/acp/message_editor.rs +++ b/crates/agent_ui/src/acp/message_editor.rs @@ -598,6 +598,25 @@ impl MessageEditor { ), ); } + + self.editor.update(cx, |editor, cx| { + editor.request_autoscroll(editor::scroll::Autoscroll::fit(), cx); + }); + + cx.spawn(async |this, cx| { + // Wait 2 frames at 120 FPS. + cx.background_executor() + .timer(Duration::from_millis(16)) + .await; + + this.update(cx, |this, cx| { + this.editor.update(cx, |editor, cx| { + editor.request_autoscroll(editor::scroll::Autoscroll::fit(), cx); + }); + }) + .ok(); + }) + .detach(); } fn confirm_mention_for_thread( diff --git a/crates/editor/src/display_map.rs b/crates/editor/src/display_map.rs index cc5d4505980fa07851d14a6cfc18095d62966bcc..87841a8f7e135663df14b4bb82e18b61cf36907e 100644 --- a/crates/editor/src/display_map.rs +++ b/crates/editor/src/display_map.rs @@ -879,15 +879,6 @@ impl DisplaySnapshot { DisplayPoint(block_point) } - pub fn point_to_display_point2(&self, point: MultiBufferPoint, bias: Bias) -> DisplayPoint { - let inlay_point = self.inlay_snapshot().to_inlay_point(point); - let fold_point = dbg!(self.fold_snapshot().to_fold_point(inlay_point, bias)); - let tab_point = self.tab_snapshot().to_tab_point(fold_point); - let wrap_point = self.wrap_snapshot().tab_point_to_wrap_point(tab_point); - let block_point = self.block_snapshot.to_block_point(wrap_point); - DisplayPoint(block_point) - } - pub fn display_point_to_point(&self, point: DisplayPoint, bias: Bias) -> Point { self.inlay_snapshot() .to_buffer_point(self.display_point_to_inlay_point(point, bias)) diff --git a/crates/editor/src/display_map/fold_map.rs b/crates/editor/src/display_map/fold_map.rs index 9c5e39c7a337141798687c94f3f226540635557b..e5d82f8f70a9b5e29622b1302c1eaaf2070b0387 100644 --- a/crates/editor/src/display_map/fold_map.rs +++ b/crates/editor/src/display_map/fold_map.rs @@ -114,9 +114,8 @@ impl FoldPoint { let overshoot = self.0 - cursor.start().1.output.lines; let mut offset = cursor.start().1.output.len; if !overshoot.is_zero() { - // todo! is this important? - // let transform = cursor.item().expect("display point out of range"); - // assert!(transform.placeholder.is_none()); + let transform = cursor.item().expect("display point out of range"); + assert!(transform.placeholder.is_none()); let end_inlay_offset = snapshot .inlay_snapshot .to_offset(InlayPoint(cursor.start().1.input.lines + overshoot)); @@ -521,17 +520,15 @@ impl FoldMap { const ELLIPSIS: &str = "⋯"; let fold_id = fold.id; - let text = " Untitled (1:10) "; - let output = TextSummary::from(text); new_transforms.push( Transform { summary: TransformSummary { - output, + output: TextSummary::from(ELLIPSIS), input: inlay_snapshot .text_summary_for_range(fold_range.start..fold_range.end), }, placeholder: Some(TransformPlaceholder { - text: text, + text: ELLIPSIS, chars: 1, renderer: ChunkRenderer { id: ChunkRendererId::Fold(fold.id), diff --git a/crates/editor/src/scroll/autoscroll.rs b/crates/editor/src/scroll/autoscroll.rs index 2ce182107e3e530e1f6bf36df1d83166d598d00f..790a15acb2c1f99cd179857e79d1e70cf7b2a1f0 100644 --- a/crates/editor/src/scroll/autoscroll.rs +++ b/crates/editor/src/scroll/autoscroll.rs @@ -158,7 +158,7 @@ impl Editor { .row() .as_f64(); target_bottom = display_map - .point_to_display_point2(selections.last().unwrap().head(), text::Bias::Left) + .point_to_display_point(selections.last().unwrap().head(), text::Bias::Left) .row() .next_row() .as_f64();