From 36ed5a31dfd1e591480be8c7550b97b479aa337b Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Thu, 18 Jan 2024 16:54:35 +0200 Subject: [PATCH] Wrap over picker's matches when reaching the end of the list --- crates/picker/src/picker.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/picker/src/picker.rs b/crates/picker/src/picker.rs index 0af4675c98..78d1c09e03 100644 --- a/crates/picker/src/picker.rs +++ b/crates/picker/src/picker.rs @@ -4,7 +4,7 @@ use gpui::{ FocusableView, Length, MouseButton, MouseDownEvent, Render, Task, UniformListScrollHandle, View, ViewContext, WindowContext, }; -use std::{cmp, sync::Arc}; +use std::sync::Arc; use ui::{prelude::*, v_flex, Color, Divider, Label, ListItem, ListItemSpacing, ListSeparator}; use workspace::ModalView; @@ -103,7 +103,7 @@ impl Picker { let count = self.delegate.match_count(); if count > 0 { let index = self.delegate.selected_index(); - let ix = cmp::min(index + 1, count - 1); + let ix = if index == count - 1 { 0 } else { index + 1 }; self.delegate.set_selected_index(ix, cx); self.scroll_handle.scroll_to_item(ix); cx.notify(); @@ -114,7 +114,7 @@ impl Picker { let count = self.delegate.match_count(); if count > 0 { let index = self.delegate.selected_index(); - let ix = index.saturating_sub(1); + let ix = if index == 0 { count - 1 } else { index - 1 }; self.delegate.set_selected_index(ix, cx); self.scroll_handle.scroll_to_item(ix); cx.notify();