From b65dc8c5666f563057164aaf01f796eaaa43ef3e Mon Sep 17 00:00:00 2001 From: Michael Sloan Date: Fri, 10 Jan 2025 22:59:21 -0700 Subject: [PATCH] Fix jank in LSP debug log autoscroll (#22998) Not sure why scroll was janky with `Autoscroll::newest()`, but this appears to fix it. Probably better to conditionally do the autoscroll requests anyway. Release Notes: - N/A --- crates/editor/src/scroll/autoscroll.rs | 6 ++++++ crates/language_tools/src/lsp_log.rs | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/editor/src/scroll/autoscroll.rs b/crates/editor/src/scroll/autoscroll.rs index a69b4a11b7453..8ae5dea7205c2 100644 --- a/crates/editor/src/scroll/autoscroll.rs +++ b/crates/editor/src/scroll/autoscroll.rs @@ -32,10 +32,16 @@ impl Autoscroll { pub fn focused() -> Self { Self::Strategy(AutoscrollStrategy::Focused) } + /// Scrolls so that the newest cursor is roughly an n-th line from the top. pub fn top_relative(n: usize) -> Self { Self::Strategy(AutoscrollStrategy::TopRelative(n)) } + + /// Scrolls so that the newest cursor is at the bottom. + pub fn bottom() -> Self { + Self::Strategy(AutoscrollStrategy::Bottom) + } } #[derive(PartialEq, Eq, Default, Clone, Copy)] diff --git a/crates/language_tools/src/lsp_log.rs b/crates/language_tools/src/lsp_log.rs index 66c6fb14d475e..01ef202227d63 100644 --- a/crates/language_tools/src/lsp_log.rs +++ b/crates/language_tools/src/lsp_log.rs @@ -642,6 +642,8 @@ impl LspLogView { log_view.editor.update(cx, |editor, cx| { editor.set_read_only(false); let last_point = editor.buffer().read(cx).len(cx); + let newest_cursor_is_at_end = + editor.selections.newest::(cx).start >= last_point; editor.edit( vec![ (last_point..last_point, entry.trim()), @@ -657,7 +659,10 @@ impl LspLogView { cx, ); } - editor.request_autoscroll(Autoscroll::fit(), cx); + + if newest_cursor_is_at_end { + editor.request_autoscroll(Autoscroll::bottom(), cx); + } editor.set_read_only(true); }); }