From 1c5b32105877ecc07ab470a6aebbf3398bf50eb3 Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Tue, 24 Oct 2023 19:29:44 +0200 Subject: [PATCH] Allow completion menus to be cycled --- crates/editor/src/editor.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index ef2c459aad..101d2297a9 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -966,8 +966,11 @@ impl CompletionsMenu { ) { if self.selected_item > 0 { self.selected_item -= 1; + } else { + self.selected_item = self.matches.len() - 1; self.list.scroll_to(ScrollTarget::Show(self.selected_item)); } + self.list.scroll_to(ScrollTarget::Show(self.selected_item)); self.attempt_resolve_selected_completion_documentation(project, cx); cx.notify(); } @@ -979,8 +982,10 @@ impl CompletionsMenu { ) { if self.selected_item + 1 < self.matches.len() { self.selected_item += 1; - self.list.scroll_to(ScrollTarget::Show(self.selected_item)); + } else { + self.selected_item = 0; } + self.list.scroll_to(ScrollTarget::Show(self.selected_item)); self.attempt_resolve_selected_completion_documentation(project, cx); cx.notify(); } @@ -1532,17 +1537,23 @@ impl CodeActionsMenu { fn select_prev(&mut self, cx: &mut ViewContext) { if self.selected_item > 0 { self.selected_item -= 1; + } else { + self.selected_item = self.actions.len() - 1; self.list.scroll_to(ScrollTarget::Show(self.selected_item)); - cx.notify() } + self.list.scroll_to(ScrollTarget::Show(self.selected_item)); + cx.notify(); } fn select_next(&mut self, cx: &mut ViewContext) { if self.selected_item + 1 < self.actions.len() { self.selected_item += 1; self.list.scroll_to(ScrollTarget::Show(self.selected_item)); - cx.notify() + } else { + self.selected_item = 0; + self.list.scroll_to(ScrollTarget::Show(self.selected_item)); } + cx.notify(); } fn select_last(&mut self, cx: &mut ViewContext) {