diff --git a/crates/editor/src/scroll/autoscroll.rs b/crates/editor/src/scroll/autoscroll.rs index deed5333f8..5e5a519262 100644 --- a/crates/editor/src/scroll/autoscroll.rs +++ b/crates/editor/src/scroll/autoscroll.rs @@ -27,7 +27,7 @@ impl Autoscroll { Self::Strategy(AutoscrollStrategy::Center) } - /// scrolls so the neweset cursor is near the top + /// scrolls so the newest cursor is near the top /// (offset by vertical_scroll_margin) pub fn focused() -> Self { Self::Strategy(AutoscrollStrategy::Focused) diff --git a/crates/repl/src/session.rs b/crates/repl/src/session.rs index 61de18401f..7deeb1a12c 100644 --- a/crates/repl/src/session.rs +++ b/crates/repl/src/session.rs @@ -7,6 +7,7 @@ use editor::{ display_map::{ BlockContext, BlockDisposition, BlockId, BlockProperties, BlockStyle, RenderBlock, }, + scroll::Autoscroll, Anchor, AnchorRangeExt as _, Editor, MultiBuffer, ToPoint, }; use futures::{FutureExt as _, StreamExt as _}; @@ -329,6 +330,8 @@ impl Session { return; }; + let new_cursor_pos = editor_block.invalidation_anchor; + self.blocks .insert(message.header.msg_id.clone(), editor_block); @@ -352,6 +355,13 @@ impl Session { } _ => {} } + + // Now move the cursor to after the block + editor.update(cx, move |editor, cx| { + editor.change_selections(Some(Autoscroll::top_relative(8)), cx, |selections| { + selections.select_ranges([new_cursor_pos..new_cursor_pos]); + }); + }); } fn route(&mut self, message: &JupyterMessage, cx: &mut ViewContext) {