fix(cmp): use tabbing for selecting completion
This commit is contained in:
+34
-12
@@ -39,6 +39,7 @@ return {
|
|||||||
end,
|
end,
|
||||||
build = (require("utils").os_name ~= "Windows_NT" and "make install_jsregexp" or nil),
|
build = (require("utils").os_name ~= "Windows_NT" and "make install_jsregexp" or nil),
|
||||||
version = "2.*",
|
version = "2.*",
|
||||||
|
dependencies = { "rafamadriz/friendly-snippets" },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
config = function()
|
config = function()
|
||||||
@@ -49,7 +50,10 @@ return {
|
|||||||
|
|
||||||
---@type cmp.ConfigSchema
|
---@type cmp.ConfigSchema
|
||||||
local opts = {
|
local opts = {
|
||||||
preselect = cmp.PreselectMode.None,
|
-- enabled = function()
|
||||||
|
-- return has_words_before()
|
||||||
|
-- end,
|
||||||
|
preselect = 'None',
|
||||||
completion = {
|
completion = {
|
||||||
autocomplete = { "InsertEnter", "TextChanged" },
|
autocomplete = { "InsertEnter", "TextChanged" },
|
||||||
keyword_length = 1,
|
keyword_length = 1,
|
||||||
@@ -78,30 +82,48 @@ return {
|
|||||||
},
|
},
|
||||||
|
|
||||||
mapping = {
|
mapping = {
|
||||||
["<Tab>"] = cmp.mapping.select_next_item({
|
["<tab>"] = cmp.mapping(function(fallback)
|
||||||
|
if cmp.visible() then
|
||||||
|
cmp.select_next_item({
|
||||||
behavior = cmp.SelectBehavior.Select,
|
behavior = cmp.SelectBehavior.Select,
|
||||||
}),
|
})
|
||||||
["<S-tab>"] = cmp.mapping.select_prev_item({
|
else
|
||||||
|
fallback()
|
||||||
|
end
|
||||||
|
end),
|
||||||
|
["<S-tab>"] = cmp.mapping(function(fallback)
|
||||||
|
if cmp.visible() then
|
||||||
|
cmp.select_prev_item({
|
||||||
behavior = cmp.SelectBehavior.Select,
|
behavior = cmp.SelectBehavior.Select,
|
||||||
}),
|
})
|
||||||
|
else
|
||||||
|
fallback()
|
||||||
|
end
|
||||||
|
end),
|
||||||
["<C-n>"] = cmp.mapping.select_next_item({
|
["<C-n>"] = cmp.mapping.select_next_item({
|
||||||
behavior = cmp.SelectBehavior.Select,
|
behavior = cmp.SelectBehavior.Select,
|
||||||
}),
|
}),
|
||||||
["<C-p>"] = cmp.mapping.select_prev_item({
|
["<C-p>"] = cmp.mapping.select_prev_item({
|
||||||
behavior = cmp.SelectBehavior.Select,
|
behavior = cmp.SelectBehavior.Select,
|
||||||
}),
|
}),
|
||||||
["<CR>"] = cmp.mapping.confirm({
|
["<CR>"] = cmp.mapping(function(fallback)
|
||||||
select = true,
|
if cmp.visible() and cmp.get_active_entry() then
|
||||||
|
cmp.confirm({
|
||||||
|
select = false,
|
||||||
behavior = cmp.ConfirmBehavior.Replace,
|
behavior = cmp.ConfirmBehavior.Replace,
|
||||||
}),
|
})
|
||||||
|
else
|
||||||
|
fallback()
|
||||||
|
end
|
||||||
|
end),
|
||||||
["<C-y>"] = cmp.mapping.confirm({
|
["<C-y>"] = cmp.mapping.confirm({
|
||||||
select = true,
|
select = true,
|
||||||
behavior = cmp.ConfirmBehavior.Replace,
|
behavior = cmp.ConfirmBehavior.Replace,
|
||||||
}),
|
}),
|
||||||
["<C-x><C-o>"] = cmp.mapping.complete(),
|
["<C-x><C-o>"] = cmp.mapping.complete(),
|
||||||
["<C-l>"] = function(fallback)
|
["<C-l>"] = function(fallback)
|
||||||
if luasnip.expand_or_locally_jumpable() then
|
if luasnip.locally_jumpable(1) then
|
||||||
luasnip.expand_or_jump()
|
luasnip.jump(1)
|
||||||
else
|
else
|
||||||
fallback()
|
fallback()
|
||||||
end
|
end
|
||||||
@@ -116,13 +138,13 @@ return {
|
|||||||
},
|
},
|
||||||
sources = {
|
sources = {
|
||||||
{ name = "nvim_lsp" },
|
{ name = "nvim_lsp" },
|
||||||
-- { name = "luasnip", },
|
{ name = "luasnip" },
|
||||||
{ name = "orgmode" },
|
{ name = "orgmode" },
|
||||||
{ name = "path" },
|
{ name = "path" },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if utils.try_require("moonfly") then
|
if utils.has_module("moonfly") then
|
||||||
local winhighlight = {
|
local winhighlight = {
|
||||||
winhighlight = "Normal:NormalFloat,FloatBorder:FloatBorder,CursorLine:PmenuSel",
|
winhighlight = "Normal:NormalFloat,FloatBorder:FloatBorder,CursorLine:PmenuSel",
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user