Skip to content

Commit

Permalink
Fix jank in LSP debug log autoscroll (#22998)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mgsloan authored Jan 11, 2025
1 parent bbbd1e9 commit b65dc8c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions crates/editor/src/scroll/autoscroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
7 changes: 6 additions & 1 deletion crates/language_tools/src/lsp_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<usize>(cx).start >= last_point;
editor.edit(
vec![
(last_point..last_point, entry.trim()),
Expand All @@ -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);
});
}
Expand Down

0 comments on commit b65dc8c

Please sign in to comment.