diff --git a/lua/modules/configs/completion/cmp.lua b/lua/modules/configs/completion/cmp.lua index 93ef41ea2..328b29b07 100644 --- a/lua/modules/configs/completion/cmp.lua +++ b/lua/modules/configs/completion/cmp.lua @@ -21,7 +21,18 @@ return function() } end - local cmp_window = require("cmp.utils.window") + ---Handling situations where LuaSnip failed to perform any jumps + ---@param r integer @Cursor position (row) before calling LuaSnip + ---@param c integer @Cursor position (col) before calling LuaSnip + ---@param fallback function @Fallback function inherited from cmp + local luasnip_fallback = vim.schedule_wrap(function(r, c, fallback) + local _r, _c = unpack(vim.api.nvim_win_get_cursor(0)) + if _r == r and _c == c then + fallback() + end + end) + + local cmp_window = require("cmp.utils.window") cmp_window.info_ = cmp_window.info cmp_window.info = function(self) @@ -97,7 +108,9 @@ return function() if cmp.visible() then cmp.select_next_item() elseif require("luasnip").expand_or_locally_jumpable() then - vim.fn.feedkeys(t("luasnip-expand-or-jump"), "") + local _r, _c = unpack(vim.api.nvim_win_get_cursor(0)) + vim.fn.feedkeys(t("luasnip-expand-or-jump")) + luasnip_fallback(_r, _c, fallback) else fallback() end