Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 3 additions & 65 deletions lua/config/autocmds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)" })
25 changes: 7 additions & 18 deletions lua/config/term.lua
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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")
Expand Down
8 changes: 0 additions & 8 deletions lua/plugins/snaks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
{
Expand Down
Loading