Skip to content

Commit

Permalink
fix: explicitely check if we try to execute an auto which-key mapping…
Browse files Browse the repository at this point in the history
…. shouldn't happen, but still safer to check
  • Loading branch information
folke committed Apr 30, 2021
1 parent 490e4d5 commit 30fdd46
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lua/which-key/keys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -311,19 +311,22 @@ function M.get_tree(mode, buf)
return M.mappings[idx]
end

function M.is_hook(prefix, cmd)
-- skip mappings with our secret nop command
local has_secret = prefix:find(secret)
-- skip auto which-key mappings
local has_wk = cmd:find("which%-key") and cmd:find("auto")
return has_wk or has_secret
end

---@param mode string
---@param buf number
function M.update_keymaps(mode, buf)
---@type Keymap
local keymaps = buf and vim.api.nvim_buf_get_keymap(buf, mode) or vim.api.nvim_get_keymap(mode)
local tree = M.get_tree(mode, buf).tree
for _, keymap in pairs(keymaps) do
-- skip mappings with our secret nop command
local has_secret = keymap.lhs:find(secret)
-- skip auto which-key mappings
local has_wk = keymap.rhs:find("which%-key") and keymap.rhs:find("auto")

local skip = has_secret or has_wk
local skip = M.is_hook(keymap.lhs, keymap.rhs)

-- check if <leader> was remapped
if not skip and Util.t(keymap.lhs) == Util.t("<leader>") then
Expand Down
8 changes: 8 additions & 0 deletions lua/which-key/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ end

function M.execute(prefix, mode, buf)

local global_node = Keys.get_tree(mode).tree:get(prefix)
local buf_node = buf and Keys.get_tree(mode, buf).tree:get(prefix) or nil

if global_node and global_node.mapping and Keys.is_hook(prefix, global_node.mapping.cmd) then
return
end
if buf_node and buf_node.mapping and Keys.is_hook(prefix, buf_node.mapping.cmd) then return end

local hooks = {}

local function unhook(nodes, nodes_buf)
Expand Down

0 comments on commit 30fdd46

Please sign in to comment.