From f0f7e77e431dd6d035f890a60a26c4abd36ab399 Mon Sep 17 00:00:00 2001 From: exochron Date: Sun, 5 Nov 2023 08:56:21 +0100 Subject: [PATCH] feat(ui): press Home/End key to select first/last mount in list --- UI/Hotkeys.lua | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/UI/Hotkeys.lua b/UI/Hotkeys.lua index 477d773..15c10f4 100644 --- a/UI/Hotkeys.lua +++ b/UI/Hotkeys.lua @@ -3,6 +3,8 @@ local _, ADDON = ... -- Keyboard Shortcuts: -- UP: Select Previous Mount -- DOWN: Select Next Mount +-- HOME: Select first Mount +-- END: Select last Mount local function FetchCurrentSelectedIndex() local target = MountJournal.selectedMountID @@ -13,24 +15,27 @@ local function FetchCurrentSelectedIndex() end end +local function JumpTo(index) + MountJournal.ScrollBox:ScrollToElementDataIndex(index) + local frame = MountJournal.ScrollBox:FindFrame(MountJournal.ScrollBox:Find(index)) + if frame then + frame:Click() + end +end + local function Select(step, totalDisplayed) local currentIndex = FetchCurrentSelectedIndex() - local index if currentIndex == nil then - index = 1 - else - index = currentIndex + step - if index < 1 then - index = 1 - elseif index > totalDisplayed then - index = totalDisplayed - end + return JumpTo(1) end - MountJournal.ScrollBox:ScrollToElementDataIndex(index) - local frame = MountJournal.ScrollBox:FindFrame(MountJournal.ScrollBox:Find(index)) - if frame then - frame:Click() + local index = currentIndex + step + if index < 1 then + JumpTo(1) + elseif index > totalDisplayed then + JumpTo(totalDisplayed) + else + JumpTo(index) end end @@ -44,14 +49,18 @@ ADDON.Events:RegisterCallback("loadUI", function() scrollFrame:EnableKeyboard(true) scrollFrame:HookScript("OnKeyDown", function(self, key) local totalDisplayed - if (key == "DOWN" or key == "UP") and ADDON.settings.ui.enableCursorKeys and not IsModifierKeyDown() then + if (key == "DOWN" or key == "UP" or key == "HOME" or key == "END") and ADDON.settings.ui.enableCursorKeys and not IsModifierKeyDown() then totalDisplayed = ADDON.Api:GetDataProvider():GetSize() if totalDisplayed > 0 then - local step = 1 - if key == "UP" then - step = -1 + if key == "END" then + JumpTo(totalDisplayed) + elseif key == "HOME" then + JumpTo(1) + elseif key == "UP" then + Select(-1, totalDisplayed) + elseif key == "DOWN" then + Select(1, totalDisplayed) end - Select(step, totalDisplayed) self:SetPropagateKeyboardInput(false) return