From cce042045e8ebc7d869003f7ccfe525a598b0677 Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Sat, 7 Jun 2025 17:34:01 +0200 Subject: [PATCH] wrap scrolling items with arrow keys and simplify scrolling logic --- Source/Editor/GUI/ItemsListContextMenu.cs | 51 +++++++++-------------- 1 file changed, 19 insertions(+), 32 deletions(-) diff --git a/Source/Editor/GUI/ItemsListContextMenu.cs b/Source/Editor/GUI/ItemsListContextMenu.cs index 82699e55c..58f8c2eb4 100644 --- a/Source/Editor/GUI/ItemsListContextMenu.cs +++ b/Source/Editor/GUI/ItemsListContextMenu.cs @@ -563,8 +563,17 @@ namespace FlaxEditor.GUI case KeyboardKeys.Escape: Hide(); return true; + case KeyboardKeys.Backspace: + // Alow the user to quickly focus the searchbar + if (_searchBox != null && !_searchBox.IsFocused) + { + _searchBox.Focus(); + _searchBox.SelectAll(); + return true; + } + break; case KeyboardKeys.ArrowDown: - { + case KeyboardKeys.ArrowUp: if (RootWindow.FocusedControl == null) { // Focus search box if nothing is focused @@ -572,39 +581,17 @@ namespace FlaxEditor.GUI return true; } - // Focus the first visible item or then next one + // Get the next item var items = GetVisibleItems(); var focusedIndex = items.IndexOf(focusedItem); - if (focusedIndex == -1) - focusedIndex = -1; - if (focusedIndex + 1 < items.Count) - { - var item = items[focusedIndex + 1]; - item.Focus(); - _scrollPanel.ScrollViewTo(item); - return true; - } - break; - } - case KeyboardKeys.ArrowUp: - if (focusedItem != null) - { - // Focus the previous visible item or the search box - var items = GetVisibleItems(); - var focusedIndex = items.IndexOf(focusedItem); - if (focusedIndex == 0) - { - _searchBox?.Focus(); - } - else if (focusedIndex > 0) - { - var item = items[focusedIndex - 1]; - item.Focus(); - _scrollPanel.ScrollViewTo(item); - return true; - } - } - break; + int delta = key == KeyboardKeys.ArrowDown ? -1 : 1; + int nextIndex = Mathf.Wrap(focusedIndex - delta, 0, items.Count - 1); + var nextItem = items[nextIndex]; + + // Focus the next item + nextItem.Focus(); + _scrollPanel.ScrollViewTo(nextItem); + return true; case KeyboardKeys.Return: if (focusedItem != null) {