Skip to content

Commit

Permalink
fix: plugin actions & spelling
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jul 10, 2024
1 parent fe53d38 commit 98ccc01
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
3 changes: 2 additions & 1 deletion lua/which-key/plugins/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ function PluginNode:__index(k)
parent = self,
desc = item.desc,
order = i,
keymap = item,
value = item.value,
action = item.action,
}
ret[item.key] = child
end
Expand Down
6 changes: 3 additions & 3 deletions lua/which-key/plugins/spelling.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ function M.expand()
local suggestions = vim.fn.spellsuggest(word, M.opts.suggestions or 20, bad[2] == "caps" and 1 or 0)

local items = {} ---@type wk.Plugin.item[]
local keys = "1234567890abcdefghijklmnopqrstuvwxyz"
local keys = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

for i, label in ipairs(suggestions) do
local key = keys:sub(i, i)

table.insert(items, {
key = key,
desc = label,
fn = function()
vim.cmd('norm! "_ciw' .. label)
action = function()
vim.cmd("norm! " .. i .. "z=")
end,
})
end
Expand Down
7 changes: 6 additions & 1 deletion lua/which-key/state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,20 @@ function M.step(state)
if node then
local is_group = Tree.is_group(node)
local is_nowait = node.keymap and node.keymap.nowait == 1
local is_action = node.action ~= nil
local is_keymap = node.keymap ~= nil

if is_group and not is_nowait then
if is_group and not is_nowait and not is_action then
return node
end
end

state.mode:reattach(node or state.node)

if node and node.action then
return node.action()
end

local keys = vim.deepcopy(state.node.path)
keys[#keys + 1] = key

Expand Down
2 changes: 2 additions & 0 deletions lua/which-key/tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ local Util = require("which-key.util")
---@field keymap? wk.Keymap
---@field order? number
---@field children? table<string, wk.Node>
---@field value? string
---@field action? fun()

---@class wk.Tree
---@field root wk.Node
Expand Down
4 changes: 2 additions & 2 deletions lua/which-key/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
---@field key string
---@field value string
---@field desc string
---@field cmd string
---@field highlights table
---@field highlights? table
---@field action? fun()

---@class wk.Plugin.action
---@field trigger string
Expand Down

0 comments on commit 98ccc01

Please sign in to comment.