Skip to content

Commit

Permalink
feat: allow disabling any trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jul 12, 2024
1 parent b8fb714 commit 94b7951
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lua/which-key/buf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,16 @@ function Mode:_attach(node)
if not self.buf:valid() then
return
end
self.triggers[node.keys] = node
local delay = require("which-key.state").delay({
local ctx = {
mode = self.mode,
keys = node.keys,
plugin = node.plugin,
})
}
if Config.disable.trigger(ctx) then
return
end
self.triggers[node.keys] = node
local delay = require("which-key.state").delay(ctx)
local waited = vim.o.timeout and delay >= vim.o.timeoutlen and vim.o.timeoutlen or 0
vim.keymap.set(self.mode, node.keys, function()
require("which-key.state").start({
Expand Down
5 changes: 5 additions & 0 deletions lua/which-key/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ local defaults = {
-- disable WhichKey for certain buf types and file types.
ft = {},
bt = {},
-- disable a trigger for a certain context by returning true
---@type fun(ctx: { keys: string, mode: string, plugin?: string }):boolean?
trigger = function(ctx)
return false
end,
},
}

Expand Down

0 comments on commit 94b7951

Please sign in to comment.