This commit is contained in:
Conrad Irwin 2023-11-14 11:03:55 -07:00
parent 7d94d8940c
commit f4ccff7b72
4 changed files with 92 additions and 12 deletions

View file

@ -58,7 +58,7 @@ impl<D: PickerDelegate> Picker<D> {
self.editor.update(cx, |editor, cx| editor.focus(cx));
}
fn select_next(&mut self, _: &menu::SelectNext, cx: &mut ViewContext<Self>) {
pub fn select_next(&mut self, _: &menu::SelectNext, cx: &mut ViewContext<Self>) {
let count = self.delegate.match_count();
if count > 0 {
let index = self.delegate.selected_index();
@ -98,6 +98,15 @@ impl<D: PickerDelegate> Picker<D> {
}
}
pub fn cycle_selection(&mut self, cx: &mut ViewContext<Self>) {
let count = self.delegate.match_count();
let index = self.delegate.selected_index();
let new_index = if index + 1 == count { 0 } else { index + 1 };
self.delegate.set_selected_index(new_index, cx);
self.scroll_handle.scroll_to_item(new_index);
cx.notify();
}
fn cancel(&mut self, _: &menu::Cancel, cx: &mut ViewContext<Self>) {
self.delegate.dismissed(cx);
}