diff --git a/crates/ai/src/assistant.rs b/crates/ai/src/assistant.rs index 39309fd361003fbc234af01089d2bb98705dc98a..e733f4d477116e0e732ada0c5cd30567cda0e7c5 100644 --- a/crates/ai/src/assistant.rs +++ b/crates/ai/src/assistant.rs @@ -1055,8 +1055,8 @@ impl AssistantEditor { }) .collect::>(); - editor.remove_blocks(old_blocks, cx); - let ids = editor.insert_blocks(new_blocks, cx); + editor.remove_blocks(old_blocks, None, cx); + let ids = editor.insert_blocks(new_blocks, None, cx); self.blocks = HashSet::from_iter(ids); }); } diff --git a/crates/diagnostics/src/diagnostics.rs b/crates/diagnostics/src/diagnostics.rs index 12fcc1395bf5a430452f1647cc197aa07df91f4b..5350e53d6aef0cff11b8d7d96b148bcb3a701af3 100644 --- a/crates/diagnostics/src/diagnostics.rs +++ b/crates/diagnostics/src/diagnostics.rs @@ -430,7 +430,7 @@ impl ProjectDiagnosticsEditor { }); self.editor.update(cx, |editor, cx| { - editor.remove_blocks(blocks_to_remove, cx); + editor.remove_blocks(blocks_to_remove, None, cx); let block_ids = editor.insert_blocks( blocks_to_add.into_iter().map(|block| { let (excerpt_id, text_anchor) = block.position; @@ -442,6 +442,7 @@ impl ProjectDiagnosticsEditor { disposition: block.disposition, } }), + Some(Autoscroll::fit()), cx, ); diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 4fef94a9bbe737c50f2346c97104de289035c3ab..6e06c901f0a10dbd9a9d6edd281d8b49c6b1de19 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -6268,6 +6268,7 @@ impl Editor { }), disposition: BlockDisposition::Below, }], + Some(Autoscroll::fit()), cx, )[0]; this.pending_rename = Some(RenameState { @@ -6334,7 +6335,11 @@ impl Editor { cx: &mut ViewContext, ) -> Option { let rename = self.pending_rename.take()?; - self.remove_blocks([rename.block_id].into_iter().collect(), cx); + self.remove_blocks( + [rename.block_id].into_iter().collect(), + Some(Autoscroll::fit()), + cx, + ); self.clear_text_highlights::(cx); self.show_local_selections = true; @@ -6720,29 +6725,43 @@ impl Editor { pub fn insert_blocks( &mut self, blocks: impl IntoIterator>, + autoscroll: Option, cx: &mut ViewContext, ) -> Vec { let blocks = self .display_map .update(cx, |display_map, cx| display_map.insert_blocks(blocks, cx)); - self.request_autoscroll(Autoscroll::fit(), cx); + if let Some(autoscroll) = autoscroll { + self.request_autoscroll(autoscroll, cx); + } blocks } pub fn replace_blocks( &mut self, blocks: HashMap, + autoscroll: Option, cx: &mut ViewContext, ) { self.display_map .update(cx, |display_map, _| display_map.replace_blocks(blocks)); - self.request_autoscroll(Autoscroll::fit(), cx); + if let Some(autoscroll) = autoscroll { + self.request_autoscroll(autoscroll, cx); + } } - pub fn remove_blocks(&mut self, block_ids: HashSet, cx: &mut ViewContext) { + pub fn remove_blocks( + &mut self, + block_ids: HashSet, + autoscroll: Option, + cx: &mut ViewContext, + ) { self.display_map.update(cx, |display_map, cx| { display_map.remove_blocks(block_ids, cx) }); + if let Some(autoscroll) = autoscroll { + self.request_autoscroll(autoscroll, cx); + } } pub fn longest_row(&self, cx: &mut AppContext) -> u32 { diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rs index d256a0424d4f0d1e34b3e51fc47a969eb4f0f908..e2b876f4b763916f855c6d501bec50109b9cc8c0 100644 --- a/crates/editor/src/editor_tests.rs +++ b/crates/editor/src/editor_tests.rs @@ -2495,6 +2495,7 @@ fn test_move_line_up_down_with_blocks(cx: &mut TestAppContext) { height: 1, render: Arc::new(|_| Empty::new().into_any()), }], + Some(Autoscroll::fit()), cx, ); editor.change_selections(None, cx, |s| { diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index e1b925d4eabce68edc1cf6bcc9a50072287c8e0a..d6f9a2e90682f72d33d06ee1b37d813e35764094 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -2883,6 +2883,7 @@ mod tests { position: Anchor::min(), render: Arc::new(|_| Empty::new().into_any()), }], + None, cx, );