Add select_first and select_last bindings to outline view

Co-Authored-By: Antonio Scandurra <me@as-cii.com>
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Max Brunsfeld 2022-01-14 10:45:37 -08:00
parent ea69dcd42a
commit b7561c6cef
8 changed files with 66 additions and 47 deletions

View file

@ -8,11 +8,7 @@ use gpui::{
elements::*,
fonts::{self, HighlightStyle},
geometry::vector::Vector2F,
keymap::{
self,
menu::{SelectNext, SelectPrev},
Binding,
},
keymap::{self, Binding},
AppContext, Axis, Entity, MutableAppContext, RenderContext, View, ViewContext, ViewHandle,
WeakViewHandle,
};
@ -24,21 +20,24 @@ use std::{
ops::Range,
sync::Arc,
};
use workspace::{Settings, Workspace};
use workspace::{
menu::{Confirm, SelectFirst, SelectLast, SelectNext, SelectPrev},
Settings, Workspace,
};
action!(Toggle);
action!(Confirm);
pub fn init(cx: &mut MutableAppContext) {
cx.add_bindings([
Binding::new("cmd-shift-O", Toggle, Some("Editor")),
Binding::new("escape", Toggle, Some("OutlineView")),
Binding::new("enter", Confirm, Some("OutlineView")),
]);
cx.add_action(OutlineView::toggle);
cx.add_action(OutlineView::confirm);
cx.add_action(OutlineView::select_prev);
cx.add_action(OutlineView::select_next);
cx.add_action(OutlineView::select_first);
cx.add_action(OutlineView::select_last);
}
struct OutlineView {
@ -197,6 +196,14 @@ impl OutlineView {
}
}
fn select_first(&mut self, _: &SelectFirst, cx: &mut ViewContext<Self>) {
self.select(0, true, false, cx);
}
fn select_last(&mut self, _: &SelectLast, cx: &mut ViewContext<Self>) {
self.select(self.matches.len().saturating_sub(1), true, false, cx);
}
fn select(&mut self, index: usize, navigate: bool, center: bool, cx: &mut ViewContext<Self>) {
self.selected_match_index = index;
self.list_state.scroll_to(if center {