Skip to content

Commit d6122bc

Browse files
authored
fix(healthcheck): use whichkey.add instead of whichkey.register
1 parent ec9925b commit d6122bc

File tree

2 files changed

+25
-33
lines changed

2 files changed

+25
-33
lines changed

lua/textcase/extensions/whichkey.lua

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
local M = {}
22

3-
function M.register(mode, mappings)
4-
local opts = {
5-
n = {
6-
mode = "n",
7-
buffer = nil,
8-
silent = true,
9-
noremap = true,
10-
nowait = true,
11-
},
12-
x = {
13-
mode = "x",
14-
buffer = nil,
15-
silent = true,
16-
noremap = true,
17-
nowait = true,
18-
},
19-
}
20-
3+
function M.register_prefix(mode, prefix, name)
214
local ok, whichkey = pcall(require, "which-key")
225
if ok then
23-
whichkey.register(mappings, opts[mode])
6+
if whichkey.add then
7+
-- whichkey.register() is deprecated in favor of whichkey.add()
8+
whichkey.add({
9+
prefix,
10+
group = name,
11+
mode = mode,
12+
buffer = nil,
13+
silent = true,
14+
noremap = true,
15+
nowait = true,
16+
})
17+
else
18+
-- fallback to whichkey.register() if whichkey.add() is unavailable
19+
whichkey.register({ [prefix] = { name = name } }, {
20+
mode = mode,
21+
buffer = nil,
22+
silent = true,
23+
noremap = true,
24+
nowait = true,
25+
})
26+
end
2427
end
2528
end
2629

lua/textcase/plugin/presets.lua

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,9 @@ local all_methods = {
2323

2424
-- Setup default keymappings for the plugin but only for the methods that are enabled.
2525
local function setup_default_keymappings()
26-
whichkey.register("x", {
27-
[M.options.prefix] = {
28-
name = "text-case",
29-
},
30-
})
31-
32-
whichkey.register("n", {
33-
[M.options.prefix] = {
34-
name = "text-case",
35-
o = {
36-
name = "Pending mode operator",
37-
},
38-
},
39-
})
26+
whichkey.register_prefix("x", M.options.prefix, "text-case")
27+
whichkey.register_prefix("n", M.options.prefix, "text-case")
28+
whichkey.register_prefix("n", M.options.prefix .. "o", "Pending mode operator")
4029

4130
local default_keymapping_definitions = {
4231
{ method_name = "to_constant_case", quick_replace = "n", operator = "on", lsp_rename = "N" },

0 commit comments

Comments
 (0)