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
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 75 additions and 27 deletions

View file

@ -3,8 +3,8 @@ use editor::{scroll::Autoscroll, Editor};
use gpui::{
actions, div, impl_actions, list, prelude::*, uniform_list, AnyElement, AppContext, ClickEvent,
DismissEvent, EventEmitter, FocusHandle, FocusableView, Length, ListSizingBehavior, ListState,
MouseButton, MouseUpEvent, Render, Task, UniformListScrollHandle, View, ViewContext,
WindowContext,
MouseButton, MouseUpEvent, Render, ScrollStrategy, Task, UniformListScrollHandle, View,
ViewContext, WindowContext,
};
use head::Head;
use serde::Deserialize;
@ -495,7 +495,9 @@ impl<D: PickerDelegate> Picker<D> {
fn scroll_to_item_index(&mut self, ix: usize) {
match &mut self.element_container {
ElementContainer::List(state) => state.scroll_to_reveal_item(ix),
ElementContainer::UniformList(scroll_handle) => scroll_handle.scroll_to_item(ix),
ElementContainer::UniformList(scroll_handle) => {
scroll_handle.scroll_to_item(ix, ScrollStrategy::Top)
}
}
}