From a634c09058844d02ce6bd7f1105e56d4e7df7d76 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Wed, 1 Jan 2025 00:31:32 +0100 Subject: [PATCH] feat: sane fast default? --- lua/no-neck-pain/init.lua | 28 +++++++++++++++++++++++----- lua/no-neck-pain/main.lua | 2 +- lua/no-neck-pain/ui.lua | 1 + 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/lua/no-neck-pain/init.lua b/lua/no-neck-pain/init.lua index 22af02b..52d20fc 100644 --- a/lua/no-neck-pain/init.lua +++ b/lua/no-neck-pain/init.lua @@ -67,7 +67,7 @@ function NoNeckPain.enable(scope) _G.NoNeckPain.config = config.options end - api.debounce(scope or "public_api_enable", main.enable) + api.debounce(scope or "public_api_enable", main.enable, 10) end --- Disables the plugin, clear highlight groups and autocmds, closes side buffers and resets the internal state. @@ -106,7 +106,7 @@ function NoNeckPain.setup(opts) }) end - if _G.NoNeckPain.config.autocmds.enableOnVimEnter then + if _G.NoNeckPain.config.autocmds.enableOnVimEnter == true then vim.api.nvim_create_autocmd({ "BufEnter" }, { pattern = "*", callback = function() @@ -115,9 +115,11 @@ function NoNeckPain.setup(opts) return end - NoNeckPain.enable() + local scope = "enable_on_vim_enter" - api.debounce("enable_on_vim_enter", function() + NoNeckPain.enable(scope) + + api.debounce(scope, function() if _G.NoNeckPain.state ~= nil then pcall(vim.api.nvim_del_augroup_by_name, "NoNeckPainVimEnterAutocmd") end @@ -130,7 +132,23 @@ function NoNeckPain.setup(opts) end if _G.NoNeckPain.config.autocmds.enableOnVimEnter == "fast" then - main.enable("enable_on_vim_enter_fast") + vim.api.nvim_create_autocmd({ "BufWinEnter" }, { + pattern = "*", + callback = function() + local scope = "enable_on_vim_enter_fast" + + main.enable(scope) + + api.debounce(scope, function() + if _G.NoNeckPain.state ~= nil then + pcall(vim.api.nvim_del_augroup_by_name, "NoNeckPainVimEnterAutocmd") + end + main.init(scope) + end) + end, + group = "NoNeckPainVimEnterAutocmd", + desc = "Triggers until it finds the correct moment/buffer to enable the plugin.", + }) end if _G.NoNeckPain.config.autocmds.enableOnTabEnter then diff --git a/lua/no-neck-pain/main.lua b/lua/no-neck-pain/main.lua index ed822e3..61c9db3 100644 --- a/lua/no-neck-pain/main.lua +++ b/lua/no-neck-pain/main.lua @@ -326,7 +326,7 @@ function main.enable(scope) desc = "keeps track of the state after closing windows and deleting buffers", }) - vim.api.nvim_create_autocmd({ "WinLeave" }, { + vim.api.nvim_create_autocmd({ "WinEnter" }, { callback = function(p) vim.schedule(function() p.event = string.format("%s:skip_entering", p.event) diff --git a/lua/no-neck-pain/ui.lua b/lua/no-neck-pain/ui.lua index a2970bb..00f4193 100644 --- a/lua/no-neck-pain/ui.lua +++ b/lua/no-neck-pain/ui.lua @@ -43,6 +43,7 @@ function ui.move_sides(scope) local curr = vim.api.nvim_get_current_win() if curr ~= id then + print("here6") vim.api.nvim_set_current_win(id) end