diff --git a/README.md b/README.md index 35f3d114..f2d80ced 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,8 @@ local defaults = { spelling = { enabled = true, -- enabling this will show WhichKey when pressing z= to select spelling suggestions suggestions = 20, -- how many suggestions should be shown in the list? + -- set custom keys for spell choices (e.g. home keys) + keys = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", }, presets = { operators = true, -- adds help for operators like d, y, ... diff --git a/doc/which-key.nvim.txt b/doc/which-key.nvim.txt index 684f5cc8..7bffdea0 100644 --- a/doc/which-key.nvim.txt +++ b/doc/which-key.nvim.txt @@ -131,6 +131,8 @@ Default Options ~ spelling = { enabled = true, -- enabling this will show WhichKey when pressing z= to select spelling suggestions suggestions = 20, -- how many suggestions should be shown in the list? + -- set custom keys for spell choices (e.g. home keys) + keys = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", }, presets = { operators = true, -- adds help for operators like d, y, ... diff --git a/lua/which-key/config.lua b/lua/which-key/config.lua index 474a2943..a354d9a7 100644 --- a/lua/which-key/config.lua +++ b/lua/which-key/config.lua @@ -45,6 +45,8 @@ local defaults = { spelling = { enabled = true, -- enabling this will show WhichKey when pressing z= to select spelling suggestions suggestions = 20, -- how many suggestions should be shown in the list? + -- set custom keys for spell choices (e.g. home keys) + keys = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", }, presets = { operators = true, -- adds help for operators like d, y, ... diff --git a/lua/which-key/plugins/spelling.lua b/lua/which-key/plugins/spelling.lua index 15707d10..5ba1abae 100644 --- a/lua/which-key/plugins/spelling.lua +++ b/lua/which-key/plugins/spelling.lua @@ -18,6 +18,13 @@ M.opts = {} function M.setup(opts) M.opts = opts + -- NOTE This logic could be within opts validation + if M.opts.suggestions > string.len(M.opts.keys) then + require("which-key.util").warn( + { "Error in spelling config", "Number of suggestions exceeds provided keys" }, + { once = true } + ) + end end function M.expand() @@ -36,7 +43,7 @@ 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 = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + local keys = M.opts.keys for i, label in ipairs(suggestions) do local key = keys:sub(i, i)