From c313b524e590829d47444dd7795da66fd3440232 Mon Sep 17 00:00:00 2001 From: speed2CZ Date: Sun, 2 Mar 2025 17:17:17 +0100 Subject: [PATCH] Console improvements - search results are now sorted alphabetically - clicking on an item doesnt steal the focus from the Edit, so UP/DOWN keys can be used to keep moving through the list - the item list correctly follows the focus item and wraps around if needed --- lua/ui/dialogs/console.lua | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lua/ui/dialogs/console.lua b/lua/ui/dialogs/console.lua index a3f71dbebb..05214ddeae 100644 --- a/lua/ui/dialogs/console.lua +++ b/lua/ui/dialogs/console.lua @@ -145,7 +145,7 @@ function CreateDialog() conFuncsList.Height:Set(function() return math.min(consoleOutput.Height(), conFuncsList:GetRowHeight() * numMatches) end) - for i,v in matches do + for i,v in ipairs(matches) do conFuncsList:AddItem(v) end @@ -156,6 +156,12 @@ function CreateDialog() conFuncsList:SetSelection(conFuncsList:GetItemCount() - 1) conFuncsList:ScrollToBottom() + local oldOnClick = conFuncsList.OnClick + conFuncsList.OnClick = function(self, row, event) + oldOnClick(conFuncsList, row, event) + edit:AcquireFocus() + end + conFuncsList.OnDoubleClick = function(self, row) edit:SetText(conFuncsList:GetItem(row)) edit:AcquireFocus() @@ -175,8 +181,14 @@ function CreateDialog() edit.OnNonTextKeyPressed = function(self, keycode) local function ChangeConFuncSelection(direction) - local selection = math.max(math.min(conFuncsList:GetSelection() + direction, conFuncsList:GetItemCount() - 1), 0) + local selection = conFuncsList:GetSelection() + direction + if selection < 0 then + selection = conFuncsList:GetItemCount() - 1 + elseif selection == conFuncsList:GetItemCount() then + selection = 0 + end conFuncsList:SetSelection(selection) + conFuncsList:ShowItem(selection) raiseConFuncList = false edit:SetText(conFuncsList:GetItem(selection)) raiseConFuncList = true