From 5d904f88294d942b280f7e8eafd0f9dc82095cd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20La=C3=ADn?= Date: Thu, 8 Feb 2024 01:14:41 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(nvim):=20autocmd=20to=20fix?= =?UTF-8?q?=20luansip=20sometimes=20getting=20bugged=20when=20hitting=20ta?= =?UTF-8?q?b?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .config/nvim/lua/config/autocmds.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.config/nvim/lua/config/autocmds.lua b/.config/nvim/lua/config/autocmds.lua index cdc6361c..df99c3b3 100644 --- a/.config/nvim/lua/config/autocmds.lua +++ b/.config/nvim/lua/config/autocmds.lua @@ -90,6 +90,22 @@ au({ "BufNewFile", "BufRead" }, { vim.diagnostic.disable(0) end, }) + +-- Use the more sane snippet session leave logic. Copied from: +-- https://github.com/L3MON4D3/LuaSnip/issues/258#issuecomment-1429989436 +au("ModeChanged", { + pattern = "*", + callback = function() + if + ((vim.v.event.old_mode == "s" and vim.v.event.new_mode == "n") or vim.v.event.old_mode == "i") + and require("luasnip").session.current_nodes[vim.api.nvim_get_current_buf()] + and not require("luasnip").session.jump_active + then + require("luasnip").unlink_current() + end + end, +}) + local numbertoggle = ag("numbertoggle", { clear = true }) -- Toggle between relative/absolute line numbers au({ "BufEnter", "FocusGained", "InsertLeave", "CmdlineLeave", "WinEnter" }, {