Skip to content

Commit 9cc9b69

Browse files
committed
plugins/which-key: remove which-key logic from keymap module
1 parent a395514 commit 9cc9b69

File tree

3 files changed

+31
-31
lines changed

3 files changed

+31
-31
lines changed

modules/keymaps.nix

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -280,32 +280,15 @@ in {
280280
(config.keymaps ++ modeMapsAsList);
281281
in
282282
optionalString (mappings != [])
283-
(
284-
if config.plugins.which-key.enable
285-
then ''
286-
-- Set up keybinds {{{
287-
do
288-
local __nixvim_binds = ${helpers.toLuaObject mappings}
289-
for i, map in ipairs(__nixvim_binds) do
290-
if not map.action then
291-
require("which-key").register({[map.key] = {name = map.options.desc }})
292-
else
293-
vim.keymap.set(map.mode, map.key, map.action, map.options)
294-
end
295-
end
296-
end
297-
-- }}}
298-
''
299-
else ''
300-
-- Set up keybinds {{{
301-
do
302-
local __nixvim_binds = ${helpers.toLuaObject mappings}
303-
for i, map in ipairs(__nixvim_binds) do
304-
vim.keymap.set(map.mode, map.key, map.action, map.options)
305-
end
283+
''
284+
-- Set up keybinds {{{
285+
do
286+
local __nixvim_binds = ${helpers.toLuaObject mappings}
287+
for i, map in ipairs(__nixvim_binds) do
288+
vim.keymap.set(map.mode, map.key, map.action, map.options)
306289
end
307-
-- }}}
308-
''
309-
);
290+
end
291+
-- }}}
292+
'';
310293
};
311294
}

plugins/utils/which-key.nix

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ in {
1414

1515
package = helpers.mkPackageOption "whick-key-nvim" pkgs.vimPlugins.which-key-nvim;
1616

17+
registrations = mkOption {
18+
type = with types; attrsOf str;
19+
default = {};
20+
description = "Manually register the description of mappings.";
21+
example = {
22+
"<leader>p" = "Find git files with telescope";
23+
};
24+
};
25+
1726
plugins = {
1827
marks = helpers.defaultNullOpts.mkBool true "shows a list of your marks on ' and `";
1928

@@ -194,8 +203,14 @@ in {
194203
mkIf cfg.enable {
195204
extraPlugins = [cfg.package];
196205

197-
extraConfigLua = ''
198-
require("which-key").setup(${helpers.toLuaObject setupOptions})
199-
'';
206+
extraConfigLua =
207+
''
208+
require("which-key").setup(${helpers.toLuaObject setupOptions})
209+
''
210+
+ (
211+
optionalString (cfg.registrations != {}) ''
212+
require("which-key").register(${helpers.toLuaObject cfg.registrations})
213+
''
214+
);
200215
};
201216
}

tests/test-sources/plugins/utils/which-key.nix

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
defaults = {
77
plugins.which-key = {
88
enable = true;
9+
10+
# Simple mapping with only Description
11+
registrations."ff" = "Test";
12+
913
plugins = {
1014
marks = true;
1115
registers = true;
@@ -86,7 +90,5 @@
8690
filetypes = [];
8791
};
8892
};
89-
# Simple mapping with only Description
90-
maps.byMode.normal."ff".options.desc = "Test";
9193
};
9294
}

0 commit comments

Comments
 (0)