-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeybinds.lua
76 lines (66 loc) · 1.69 KB
/
keybinds.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
local M = {}
function M.addKeybinds(keymap, mode, buttons, name, desc, callback)
local bind = {
name = name,
desc = desc,
call = callback
}
if keymap[mode] == nil then
keymap[mode] = {}
end
for _, button in pairs(buttons) do
keymap[mode][button] = bind
end
end
function M.generateKeymap(config, generate_mode_keybinds, sticky_key)
local keybinds = {}
for mode_name, mode_config in pairs(config) do
if generate_mode_keybinds then
-- Add mode keybinds to every other mode
for to_mode_name, to_mode_config in pairs(config) do
M.addKeybinds(
keybinds,
mode_name,
to_mode_config.buttons,
to_mode_config.name,
to_mode_config.desc,
function()
print("Setting mode " .. to_mode_name)
ximMode = to_mode_name
ximSticky = false
end
)
if sticky_key then
local sticky_buttons = {}
for _, button in pairs(to_mode_config.buttons) do
table.insert(sticky_buttons, sticky_key .. button)
end
M.addKeybinds(
keybinds,
mode_name,
sticky_buttons,
to_mode_config.name,
to_mode_config.desc,
function()
ximMode = to_mode_name
ximSticky = true
end
)
end
end
end
-- Add each command
for _, command_config in pairs(mode_config.commands) do
M.addKeybinds(
keybinds,
mode_name,
command_config.buttons,
command_config.name,
command_config.desc,
command_config.call
)
end
end
return keybinds
end
return M