feat: register mapping with no actions in which-key when enabled

This commit is contained in:
Tanish2002 2023-05-20 16:26:36 +05:30 committed by Gaétan Lepage
parent 49f46d3b3d
commit 5fa54c6d39
2 changed files with 39 additions and 15 deletions

View file

@ -105,7 +105,11 @@ with lib; let
options = options =
mapConfigOptions mapConfigOptions
// { // {
action = mkOption { action =
if config.plugins.which-key.enable
then helpers.mkNullOrOption types.str "The action to execute"
else
mkOption {
type = types.str; type = types.str;
description = "The action to execute."; description = "The action to execute.";
}; };
@ -180,16 +184,34 @@ in {
++ (genMaps "!" config.maps.insertCommand) ++ (genMaps "!" config.maps.insertCommand)
++ (genMaps "c" config.maps.command); ++ (genMaps "c" config.maps.command);
in { in {
extraConfigLua = optionalString (mappings != []) '' extraConfigLua =
optionalString (mappings != [])
(
if config.plugins.which-key.enable
then ''
-- Set up keybinds {{{
do
local __nixvim_binds = ${helpers.toLuaObject mappings}
for i, map in ipairs(__nixvim_binds) do
if not map.action then
require("which-key").register({[map.key] = {name = map.config.desc }})
else
vim.keymap.set(map.mode, map.key, map.action, map.config)
end
end
end
-- }}}
''
else ''
-- Set up keybinds {{{ -- Set up keybinds {{{
do do
local __nixvim_binds = ${helpers.toLuaObject mappings} local __nixvim_binds = ${helpers.toLuaObject mappings}
for i, map in ipairs(__nixvim_binds) do for i, map in ipairs(__nixvim_binds) do
vim.keymap.set(map.mode, map.key, map.action, map.config) vim.keymap.set(map.mode, map.key, map.action, map.config)
end end
end end
-- }}} -- }}}
''; ''
);
}; };
} }

View file

@ -86,5 +86,7 @@
filetypes = []; filetypes = [];
}; };
}; };
# Simple mapping with only Description
maps.normal."ff".desc = "Test";
}; };
} }