From 69b95f891ee8e6b4c5a360239008f26442d58678 Mon Sep 17 00:00:00 2001 From: Alejandro Espinoza Date: Fri, 19 Jun 2026 14:37:48 -0600 Subject: [PATCH] refactor: drop redundant WSL workarounds after term.lua fix Remove ColorScheme debounce, CursorHold cmdline guards, and snacks auto_close now that kitty protocol flags=1 fixes double keypress at the source. Slim term.lua scheduling to init + VimEnter retries. Co-authored-by: Cursor --- lua/config/autocmds.lua | 68 ++--------------------------------------- lua/config/term.lua | 25 +++++---------- lua/plugins/snaks.lua | 8 ----- 3 files changed, 10 insertions(+), 91 deletions(-) diff --git a/lua/config/autocmds.lua b/lua/config/autocmds.lua index e5c7bfa..8d30ca9 100644 --- a/lua/config/autocmds.lua +++ b/lua/config/autocmds.lua @@ -102,74 +102,12 @@ vim.api.nvim_create_user_command( { desc = "show hi name" } ) -local in_cmdline = false -local colorscheme_picker_opening = false - -local function open_colorscheme_picker() - -- Double Enter (kitty protocol) can invoke the command twice and toggle-close. - if colorscheme_picker_opening then - return - end - colorscheme_picker_opening = true - - vim.defer_fn(function() - colorscheme_picker_opening = false - - local ok, picker_api = pcall(require, 'snacks.picker') - if not ok then - return - end - - if picker_api.get({ source = "colorschemes" })[1] then - return - end - - require("snacks").picker.colorschemes({ auto_close = false }) - end, 100) -end - -vim.api.nvim_create_autocmd("CmdlineEnter", { - callback = function() - in_cmdline = true - pcall(vim.diagnostic.hide) - end, -}) - -vim.api.nvim_create_autocmd("CmdlineLeave", { - callback = function() - in_cmdline = false - end, -}) - vim.api.nvim_create_autocmd("CursorHold", { callback = function() - if in_cmdline then - return - end - - -- Cmdline/wildmenu: avoid diagnostic float stealing focus (WSL tab completion jump). - local mode = vim.api.nvim_get_mode().mode - if mode:find("^c") or vim.fn.getcmdwintype() ~= "" then - return - end - - -- Skip floats (picker, diagnostics) so WSL/GUI terminals don't fight for focus. - if vim.api.nvim_win_get_config(0).relative ~= "" then - return - end - - local ok, picker = pcall(require, 'snacks.picker') - if ok and #picker.get() > 0 then - return - end - vim.diagnostic.open_float(nil, { focus = false }) end, }) -vim.api.nvim_create_user_command("PickColorscheme", open_colorscheme_picker, { - desc = "Pick colorscheme (Snacks picker with preview)", -}) -vim.api.nvim_create_user_command("ColorScheme", open_colorscheme_picker, { - desc = "Alias for PickColorscheme", -}) +vim.api.nvim_create_user_command("ColorScheme", function() + require("snacks").picker.colorschemes() +end, { desc = "Pick colorscheme (Snacks picker with preview)" }) diff --git a/lua/config/term.lua b/lua/config/term.lua index 3c75269..08c729e 100644 --- a/lua/config/term.lua +++ b/lua/config/term.lua @@ -1,6 +1,6 @@ local M = {} ---- Kitty/Alacritty on WSL often reports a generic $TERM; detect via env too. +--- Kitty/Alacritty on WSL often report a generic $TERM; detect via env too. function M.needs_key_protocol_fix() if vim.env.NVIM_DISABLE_KEY_PROTOCOL == "1" then return true @@ -23,37 +23,26 @@ function M.needs_key_protocol_fix() end --- Neovim 0.12+ enables kitty protocol with flags=3 (disambiguate + report key-up). ---- That makes Enter/Tab/Backspace fire on keydown and keyup in Kitty/Alacritty (#31806). ---- Push flags=1 (disambiguate only) after Neovim starts so each keypress fires once. +--- Push flags=1 after startup so Enter/Tab/Backspace fire once (#31806). function M.fix_key_protocol() io.stdout:write("\027[>1u") io.stdout:flush() end -local function schedule_fix() - for _, delay in ipairs({ 0, 50, 150, 500 }) do - vim.defer_fn(M.fix_key_protocol, delay) - end -end - function M.setup() if not M.needs_key_protocol_fix() then return end - schedule_fix() + M.fix_key_protocol() vim.api.nvim_create_autocmd("VimEnter", { - callback = schedule_fix, + callback = function() + vim.defer_fn(M.fix_key_protocol, 0) + vim.defer_fn(M.fix_key_protocol, 100) + end, }) - if vim.fn.exists("##UIEnter") == 1 then - vim.api.nvim_create_autocmd("UIEnter", { - once = true, - callback = schedule_fix, - }) - end - vim.api.nvim_create_autocmd("VimLeavePre", { callback = function() io.stdout:write("\027[<1u") diff --git a/lua/plugins/snaks.lua b/lua/plugins/snaks.lua index 2082a39..1281481 100644 --- a/lua/plugins/snaks.lua +++ b/lua/plugins/snaks.lua @@ -5,14 +5,6 @@ return { explorer = { enabled = false, }, - picker = { - sources = { - colorschemes = { - -- WSL + Kitty/Alacritty can fire spurious WinEnter events; keep picker open. - auto_close = false, - }, - }, - }, }, keys = { {