@@ -15,38 +15,8 @@ local snippet_commands = { 'snippet_forward', 'snippet_backward' }
15
15
16
16
--- @param opts blink.cmp.KeymapConfig
17
17
function keymap .setup (opts )
18
- local function handle_key (mode , key )
19
- local key_insert_commands = {}
20
- local key_snippet_commands = {}
21
-
22
- for command , keys in pairs (opts ) do
23
- keys = type (keys ) == ' string' and { keys } or keys
24
- if vim .tbl_contains (keys , key ) then
25
- if vim .tbl_contains (snippet_commands , command ) then
26
- table.insert (key_snippet_commands , command )
27
- elseif mode == ' i' and vim .tbl_contains (insert_commands , command ) then
28
- table.insert (key_insert_commands , command )
29
- else
30
- error (' Invalid command in keymap config: ' .. command )
31
- end
32
- end
33
- end
34
-
35
- for _ , command in ipairs (key_insert_commands ) do
36
- local did_run = require (' blink.cmp' )[command ]()
37
- if did_run then return end
38
- end
39
-
40
- for _ , command in ipairs (key_snippet_commands ) do
41
- local did_run = require (' blink.cmp' )[command ]()
42
- if did_run then return end
43
- end
44
-
45
- return key
46
- end
47
-
48
- local snippet_keys = {}
49
- local insert_keys = {}
18
+ local insert_keys_to_commands = {}
19
+ local snippet_keys_to_commands = {}
50
20
for command , keys in pairs (opts ) do
51
21
local is_snippet_command = vim .tbl_contains (snippet_commands , command )
52
22
local is_insert_command = vim .tbl_contains (insert_commands , command )
@@ -57,16 +27,38 @@ function keymap.setup(opts)
57
27
58
28
-- add keymaps
59
29
for _ , key in ipairs (keys ) do
60
- insert_keys [key ] = true
61
- if is_snippet_command then snippet_keys [key ] = true end
30
+ if is_insert_command then
31
+ if insert_keys_to_commands [key ] == nil then insert_keys_to_commands [key ] = {} end
32
+ table.insert (insert_keys_to_commands [key ], command )
33
+ end
34
+ if is_snippet_command then
35
+ if snippet_keys_to_commands [key ] == nil then snippet_keys_to_commands [key ] = {} end
36
+ table.insert (snippet_keys_to_commands [key ], command )
37
+ end
62
38
end
63
39
end
64
40
65
- for key , _ in pairs (insert_keys ) do
66
- vim .keymap .set (' i' , key , function () return handle_key (' i' , key ) end , { expr = true , silent = true })
41
+ for key , _ in pairs (insert_keys_to_commands ) do
42
+ vim .keymap .set (' i' , key , function ()
43
+ for _ , command in ipairs (insert_keys_to_commands [key ] or {}) do
44
+ local did_run = require (' blink.cmp' )[command ]()
45
+ if did_run then return end
46
+ end
47
+ for _ , command in ipairs (snippet_keys_to_commands [key ] or {}) do
48
+ local did_run = require (' blink.cmp' )[command ]()
49
+ if did_run then return end
50
+ end
51
+ return key
52
+ end , { expr = true , silent = true })
67
53
end
68
- for key , _ in pairs (snippet_keys ) do
69
- vim .keymap .set (' s' , key , function () return handle_key (' s' , key ) end , { expr = true , silent = true })
54
+ for key , _ in pairs (snippet_keys_to_commands ) do
55
+ vim .keymap .set (' s' , key , function ()
56
+ for _ , command in ipairs (snippet_keys_to_commands [key ] or {}) do
57
+ local did_run = require (' blink.cmp' )[command ]()
58
+ if did_run then return end
59
+ end
60
+ return key
61
+ end , { expr = true , silent = true })
70
62
end
71
63
end
72
64
0 commit comments