Skip to content

Commit

Permalink
Made it easier to remove hotkeys
Browse files Browse the repository at this point in the history
Can be removed with either scope + activator or the hotkey itself
  • Loading branch information
Cruor committed Jul 19, 2024
1 parent cccbab5 commit f988a0b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/hotkey_handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,36 @@ local tools = require("tools")
local registeredHotkeys = {}
local hotkeyHandler = {}

function hotkeyHandler.removeHotkey(scope, activator)
if utils.typeof(scope) == "hotkey" then
activator = scope._rawActivator
scope = scope.scope
end

for i, target in ipairs(registeredHotkeys) do
if target.scope == scope and target._rawActivator == activator then
table.remove(registeredHotkeys, i)

return target
end
end
end

function hotkeyHandler.addHotkey(scope, activator, callback, options)
local hotkey

if utils.typeof(scope) == "hotkey" then
hotkey = scope
end

-- Remove any previously registered hotkeys to same scope and activator
hotkeyHandler.removeHotkey(scope, activator)

hotkey = hotkeyStruct.createHotkey(scope, activator, callback, options)

table.insert(registeredHotkeys, hotkey)

return hotkey
end

function hotkeyHandler.addStandardHotkeys()
Expand Down

0 comments on commit f988a0b

Please sign in to comment.