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

View file

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