Skip to content

Commit

Permalink
revert(cmp): use default cmp.visible function for checking visibility
Browse files Browse the repository at this point in the history
Refs: a32371a
  • Loading branch information
mehalter committed Jul 8, 2024
1 parent d9edd6a commit 01a3aea
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lua/astronvim/plugins/cmp_luasnip.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ local function has_words_before()
local line, col = (unpack or table.unpack)(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match "%s" == nil
end
local function is_visible(cmp) return cmp.core.view:visible() or vim.fn.pumvisible() == 1 end

return {
{
Expand Down Expand Up @@ -127,14 +126,14 @@ return {
["<Up>"] = cmp.mapping.select_prev_item { behavior = cmp.SelectBehavior.Select },
["<Down>"] = cmp.mapping.select_next_item { behavior = cmp.SelectBehavior.Select },
["<C-P>"] = cmp.mapping(function()
if is_visible(cmp) then
if cmp.visible() then
cmp.select_prev_item()
else
cmp.complete()
end
end),
["<C-N>"] = cmp.mapping(function()
if is_visible(cmp) then
if cmp.visible() then
cmp.select_next_item()
else
cmp.complete()
Expand All @@ -149,7 +148,7 @@ return {
["<C-E>"] = cmp.mapping(cmp.mapping.abort(), { "i", "c" }),
["<CR>"] = cmp.mapping(cmp.mapping.confirm { select = false }, { "i", "c" }),
["<Tab>"] = cmp.mapping(function(fallback)
if is_visible(cmp) then
if cmp.visible() then
cmp.select_next_item()
elseif vim.api.nvim_get_mode().mode ~= "c" and vim.snippet and vim.snippet.active { direction = 1 } then
vim.schedule(function() vim.snippet.jump(1) end)
Expand All @@ -160,7 +159,7 @@ return {
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if is_visible(cmp) then
if cmp.visible() then
cmp.select_prev_item()
elseif vim.api.nvim_get_mode().mode ~= "c" and vim.snippet and vim.snippet.active { direction = -1 } then
vim.schedule(function() vim.snippet.jump(-1) end)
Expand Down Expand Up @@ -195,7 +194,7 @@ return {

if not opts.mappings then opts.mappings = {} end
opts.mapping["<Tab>"] = cmp.mapping(function(fallback)
if is_visible(cmp) then
if cmp.visible() then
cmp.select_next_item()
elseif vim.api.nvim_get_mode().mode ~= "c" and luasnip.expand_or_locally_jumpable() then
luasnip.expand_or_jump()
Expand All @@ -206,7 +205,7 @@ return {
end
end, { "i", "s" })
opts.mapping["<S-Tab>"] = cmp.mapping(function(fallback)
if is_visible(cmp) then
if cmp.visible() then
cmp.select_prev_item()
elseif vim.api.nvim_get_mode().mode ~= "c" and luasnip.jumpable(-1) then
luasnip.jump(-1)
Expand Down

0 comments on commit 01a3aea

Please sign in to comment.