Skip to content

Commit

Permalink
fix(triggers): never attach when macro is recording / executing. Fixes
Browse files Browse the repository at this point in the history
…#851. Fixes #822. Fixes #807
  • Loading branch information
folke committed Sep 18, 2024
1 parent bfec3d6 commit 6b023b4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lua/which-key/state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ function M.safe(mode_change)
local old, _new = unpack(vim.split(mode_change, ":", { plain = true }))
if old == "c" then
return false, "command-mode"
elseif vim.fn.reg_recording() ~= "" then
return false, "recording"
elseif vim.fn.reg_executing() ~= "" then
return false, "executing"
elseif Util.in_macro() then
return false, "macro"
elseif mode_change:lower() == "v:v" then
return false, "visual-block"
end
Expand Down
3 changes: 3 additions & 0 deletions lua/which-key/triggers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ function M.schedule(mode)
0,
0,
vim.schedule_wrap(function()
if Util.in_macro() then
return M.schedule()
end
for m, _ in pairs(M.suspended) do
M.suspended[m] = nil
M.attach(m)
Expand Down
4 changes: 4 additions & 0 deletions lua/which-key/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ function M.exit()
vim.api.nvim_feedkeys(M.ESC, "n", false)
end

function M.in_macro()
return vim.fn.reg_recording() ~= "" or vim.fn.reg_executing() ~= ""
end

---@param rhs string|fun()
function M.is_nop(rhs)
return type(rhs) == "string" and (rhs == "" or rhs:lower() == "<nop>")
Expand Down

0 comments on commit 6b023b4

Please sign in to comment.