From f6c3676eb278277b81d8cd41a5cca5d86aacdc22 Mon Sep 17 00:00:00 2001 From: Sandy Jackson Date: Wed, 30 Jul 2025 11:46:19 +0100 Subject: [PATCH 1/2] Add custom keys to spell module Includes checking in spelling setup() for number of keys provided. --- lua/which-key/config.lua | 2 ++ lua/which-key/plugins/spelling.lua | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) 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) From c3e14a46fd57e9875fd06182a25116e03da9b957 Mon Sep 17 00:00:00 2001 From: Sandy Jackson Date: Wed, 30 Jul 2025 12:08:17 +0100 Subject: [PATCH 2/2] Update docs for spelling keys --- README.md | 2 ++ doc/which-key.nvim.txt | 2 ++ 2 files changed, 4 insertions(+) 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 3cb7e311..2ebadca2 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, ...