@@ -2,15 +2,19 @@ local logger = require("copilot.logger")
22local config = require (" copilot.config" )
33
44local M = {}
5-
65local previous_keymaps = {}
76
87--- @param mode string
98--- @param key string
109--- @param action function
1110--- @param desc string
1211function M .register_keymap (mode , key , action , desc )
13- if not mode or not key or not action then
12+ if not key then
13+ return
14+ end
15+
16+ if not mode or not action then
17+ logger .error (" Invalid parameters to register_keymap" .. vim .inspect ({ mode , key , action , desc }))
1418 return
1519 end
1620
2731--- @param action function : boolean
2832--- @param desc string
2933function M .register_keymap_with_passthrough (mode , key , action , desc )
30- if not mode or not key or not action then
34+ if not key then
35+ return
36+ end
37+
38+ if not mode or not action then
39+ logger .error (" Invalid parameters to register_keymap_with_passthrough" .. vim .inspect ({ mode , key , action , desc }))
3140 return
3241 end
3342
@@ -41,16 +50,21 @@ function M.register_keymap_with_passthrough(mode, key, action, desc)
4150 end
4251
4352 vim .keymap .set (mode , key , function ()
44- local action_ran = action ()
45- if not action_ran then
46- -- If there was a previous mapping, execute it
53+ if action () then
54+ return " <Ignore> "
55+ else
4756 local prev = previous_keymaps [keymap_key ]
57+
4858 if prev then
4959 vim .api .nvim_feedkeys (vim .api .nvim_replace_termcodes (prev , true , false , true ), mode , true )
60+ return " <Ignore>"
5061 end
62+
63+ return key
5164 end
5265 end , {
5366 desc = desc ,
67+ expr = true ,
5468 silent = true ,
5569 })
5670end
0 commit comments