Skip to content

Commit

Permalink
fix(state): better current buf/mode check
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jul 24, 2024
1 parent 388bd3f commit 711453b
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions lua/which-key/state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,13 @@ function M.setup()
-- HACK: ModeChanged does not always trigger, so we need to manually
-- check for mode changes. This seems to be due to the usage of `:norm` in autocmds.
-- See https://github.com/folke/which-key.nvim/issues/787
local last_mode = nil ---@type string?
local last_buf = nil ---@type number?
local timer = uv.new_timer()
timer:start(0, 50, function()
local mode = vim.api.nvim_get_mode().mode
if mode == last_mode and last_buf == current_buf then
local mode = Util.mapmode()
-- check if the mode exists for the current buffer
if Buf.bufs[current_buf] and Buf.bufs[current_buf].modes[mode] then
return
end
last_mode = mode
last_buf = current_buf
vim.schedule(Buf.get)
end)
end
Expand Down

0 comments on commit 711453b

Please sign in to comment.