From c996eadaf57ae52cde3edbee3ece26283c5da54a Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Wed, 5 Nov 2025 23:22:29 +0200 Subject: [PATCH] Update editor data only after real scroll reports (#42035) Release Notes: - N/A --- crates/editor/src/editor.rs | 32 ++++++++++++++++++++++++-------- crates/editor/src/scroll.rs | 19 ++----------------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index fdd5b01744a7a2b89edfb61bfc379af203fd7058..6dcc0f2eefbd3b5b4b5d6faf5b838f9ec39add6c 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -2281,16 +2281,32 @@ impl Editor { |editor, _, e: &EditorEvent, window, cx| match e { EditorEvent::ScrollPositionChanged { local, .. } => { if *local { - let new_anchor = editor.scroll_manager.anchor(); - let snapshot = editor.snapshot(window, cx); - editor.update_restoration_data(cx, move |data| { - data.scroll_position = ( - new_anchor.top_row(snapshot.buffer_snapshot()), - new_anchor.offset, - ); - }); editor.hide_signature_help(cx, SignatureHelpHiddenBy::Escape); editor.inline_blame_popover.take(); + editor.post_scroll_update = cx.spawn_in(window, async move |editor, cx| { + cx.background_executor() + .timer(Duration::from_millis(50)) + .await; + editor + .update_in(cx, |editor, window, cx| { + editor.register_visible_buffers(cx); + editor.refresh_colors_for_visible_range(None, window, cx); + editor.refresh_inlay_hints( + InlayHintRefreshReason::NewLinesShown, + cx, + ); + + let new_anchor = editor.scroll_manager.anchor(); + let snapshot = editor.snapshot(window, cx); + editor.update_restoration_data(cx, move |data| { + data.scroll_position = ( + new_anchor.top_row(snapshot.buffer_snapshot()), + new_anchor.offset, + ); + }); + }) + .ok(); + }); } } EditorEvent::Edited { .. } => { diff --git a/crates/editor/src/scroll.rs b/crates/editor/src/scroll.rs index 001be45ab814e1627dc34abbba342272d3e15750..d98dc89b6b0f1a5ab0ebd9a910db0fcb0db1f18c 100644 --- a/crates/editor/src/scroll.rs +++ b/crates/editor/src/scroll.rs @@ -603,7 +603,7 @@ impl Editor { scroll_position }; - let editor_was_scrolled = self.scroll_manager.set_scroll_position( + self.scroll_manager.set_scroll_position( adjusted_position, &display_map, local, @@ -611,22 +611,7 @@ impl Editor { workspace_id, window, cx, - ); - - self.post_scroll_update = cx.spawn_in(window, async move |editor, cx| { - cx.background_executor() - .timer(Duration::from_millis(50)) - .await; - editor - .update_in(cx, |editor, window, cx| { - editor.register_visible_buffers(cx); - editor.refresh_colors_for_visible_range(None, window, cx); - editor.refresh_inlay_hints(InlayHintRefreshReason::NewLinesShown, cx); - }) - .ok(); - }); - - editor_was_scrolled + ) } pub fn scroll_position(&self, cx: &mut Context) -> gpui::Point {