feat(mapping): add all native mappings (#1430)
* feat(mapping): fully mimics the behavior of native `<C-n>` and `<C-p>` Signed-off-by: Wuelner Martínez <wuelner.martinez@outlook.com> * feat(mapping): added more native mappings to the `cmdline` preset Signed-off-by: Wuelner Martínez <wuelner.martinez@outlook.com> * fix(mapping): improved `<Tab>` and `<S-Tab>` mapppings of `cmdline` Signed-off-by: Wuelner Martínez <wuelner.martinez@outlook.com> --------- Signed-off-by: Wuelner Martínez <wuelner.martinez@outlook.com>
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
local types = require('cmp.types')
|
||||
local misc = require('cmp.utils.misc')
|
||||
local feedkeys = require('cmp.utils.feedkeys')
|
||||
local keymap = require('cmp.utils.keymap')
|
||||
|
||||
local function merge_keymaps(base, override)
|
||||
@@ -43,10 +42,24 @@ mapping.preset.insert = function(override)
|
||||
i = mapping.select_prev_item({ behavior = types.cmp.SelectBehavior.Select }),
|
||||
},
|
||||
['<C-n>'] = {
|
||||
i = mapping.select_next_item({ behavior = types.cmp.SelectBehavior.Insert }),
|
||||
i = function()
|
||||
local cmp = require('cmp')
|
||||
if cmp.visible() then
|
||||
cmp.select_next_item({ behavior = types.cmp.SelectBehavior.Insert })
|
||||
else
|
||||
cmp.complete()
|
||||
end
|
||||
end,
|
||||
},
|
||||
['<C-p>'] = {
|
||||
i = mapping.select_prev_item({ behavior = types.cmp.SelectBehavior.Insert }),
|
||||
i = function()
|
||||
local cmp = require('cmp')
|
||||
if cmp.visible() then
|
||||
cmp.select_prev_item({ behavior = types.cmp.SelectBehavior.Insert })
|
||||
else
|
||||
cmp.complete()
|
||||
end
|
||||
end,
|
||||
},
|
||||
['<C-y>'] = {
|
||||
i = mapping.confirm({ select = false }),
|
||||
@@ -60,13 +73,23 @@ end
|
||||
---Mapping preset cmdline-mode configuration.
|
||||
mapping.preset.cmdline = function(override)
|
||||
return merge_keymaps(override or {}, {
|
||||
['<C-z>'] = {
|
||||
c = function()
|
||||
local cmp = require('cmp')
|
||||
if cmp.visible() then
|
||||
cmp.select_next_item()
|
||||
else
|
||||
cmp.complete()
|
||||
end
|
||||
end,
|
||||
},
|
||||
['<Tab>'] = {
|
||||
c = function()
|
||||
local cmp = require('cmp')
|
||||
if cmp.visible() then
|
||||
cmp.select_next_item()
|
||||
else
|
||||
feedkeys.call(keymap.t('<C-z>'), 'n')
|
||||
cmp.complete()
|
||||
end
|
||||
end,
|
||||
},
|
||||
@@ -76,7 +99,7 @@ mapping.preset.cmdline = function(override)
|
||||
if cmp.visible() then
|
||||
cmp.select_prev_item()
|
||||
else
|
||||
feedkeys.call(keymap.t('<C-z>'), 'n')
|
||||
cmp.complete()
|
||||
end
|
||||
end,
|
||||
},
|
||||
@@ -101,7 +124,10 @@ mapping.preset.cmdline = function(override)
|
||||
end,
|
||||
},
|
||||
['<C-e>'] = {
|
||||
c = mapping.close(),
|
||||
c = mapping.abort(),
|
||||
},
|
||||
['<C-y>'] = {
|
||||
c = mapping.confirm({ select = false }),
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user