Prefer revealing items in the middle of the list for outline and project panels (#20349)

Closes https://github.com/zed-industries/zed/issues/18255

Zed does not scroll always, but only if the item is out of sight, this
is preserved for now.
Otherwise, if the item is out of sight, project and outline panels + the
syntax tree view now attempt to scroll it into the middle, if there's
enough elements above and below.

Release Notes:

- Improved revealing items for outline and project panels (now center of the list is preferred)
This commit is contained in:
Kirill Bulatov
2024-11-07 14:36:29 +02:00
committed by GitHub
parent 16cbff9118
commit 083f06322d
6 changed files with 75 additions and 27 deletions
@@ -2,8 +2,8 @@ use editor::{scroll::Autoscroll, Anchor, Editor, ExcerptId};
use gpui::{
actions, div, rems, uniform_list, AppContext, Div, EventEmitter, FocusHandle, FocusableView,
Hsla, InteractiveElement, IntoElement, Model, MouseButton, MouseDownEvent, MouseMoveEvent,
ParentElement, Render, SharedString, Styled, UniformListScrollHandle, View, ViewContext,
VisualContext, WeakView, WindowContext,
ParentElement, Render, ScrollStrategy, SharedString, Styled, UniformListScrollHandle, View,
ViewContext, VisualContext, WeakView, WindowContext,
};
use language::{Buffer, OwnedSyntaxLayer};
use std::{mem, ops::Range};
@@ -199,7 +199,8 @@ impl SyntaxTreeView {
let descendant_ix = cursor.descendant_index();
self.selected_descendant_ix = Some(descendant_ix);
self.list_scroll_handle.scroll_to_item(descendant_ix);
self.list_scroll_handle
.scroll_to_item(descendant_ix, ScrollStrategy::Center);
cx.notify();
Some(())