Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(toggle): only execute self:_wk when mapping exists #378

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
15 changes: 13 additions & 2 deletions lua/snacks/toggle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,19 @@ function Toggle:map(keys, opts)
self:toggle()
end, opts)
if self.opts.which_key then
Snacks.util.on_module("which-key", function()
self:_wk(keys, mode)
-- Needed so that it executes after `keymaps.lua` loads, otherwise it
-- wouldn't work as `Snacks.toggle.animate():map("<leader>ua") will be
-- evaluated during the parsing phase. Maybe there's a better way??
vim.schedule(function()
Snacks.util.on_module("which-key", function()
local modes = type(mode) == "string" and { mode } or mode
for _, m in ipairs(modes) do
local mapping = vim.fn.maparg(keys, m)
if mapping ~= "" then
self:_wk(keys, mode)
end
end
end)
end)
end
return self
Expand Down
Loading