mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-23 01:08:43 +02:00
lib/keymap-helpers: refactor mkMapOptionSubmodule
Make the `key` and `action` options optional, and allow configuring whether `action` can be a raw type.
This commit is contained in:
parent
87d6654a9f
commit
df3aa86713
2 changed files with 53 additions and 35 deletions
|
@ -60,7 +60,11 @@ rec {
|
||||||
# ["" "n" "v" ...]
|
# ["" "n" "v" ...]
|
||||||
(map ({ short, ... }: short) (attrValues modes));
|
(map ({ short, ... }: short) (attrValues modes));
|
||||||
|
|
||||||
mapOptionSubmodule = mkMapOptionSubmodule { };
|
mapOptionSubmodule = mkMapOptionSubmodule {
|
||||||
|
hasKey = true;
|
||||||
|
hasAction = true;
|
||||||
|
rawAction = true;
|
||||||
|
};
|
||||||
|
|
||||||
mkModeOption =
|
mkModeOption =
|
||||||
default:
|
default:
|
||||||
|
@ -79,14 +83,20 @@ rec {
|
||||||
};
|
};
|
||||||
|
|
||||||
mkMapOptionSubmodule =
|
mkMapOptionSubmodule =
|
||||||
defaults:
|
{
|
||||||
|
defaults ? { },
|
||||||
|
hasKey ? false,
|
||||||
|
hasAction ? false,
|
||||||
|
rawAction ? true,
|
||||||
|
}:
|
||||||
# TODO remove assert once `lua` option is gone
|
# TODO remove assert once `lua` option is gone
|
||||||
# This is here to ensure no uses of `mkMapOptionSubmodule` set a `lua` default
|
# This is here to ensure no uses of `mkMapOptionSubmodule` set a `lua` default
|
||||||
assert !(defaults ? lua);
|
assert !(defaults ? lua);
|
||||||
(
|
(
|
||||||
with types;
|
with types;
|
||||||
submodule {
|
submodule {
|
||||||
options = {
|
options =
|
||||||
|
(optionalAttrs hasKey {
|
||||||
key = mkOption (
|
key = mkOption (
|
||||||
{
|
{
|
||||||
type = str;
|
type = str;
|
||||||
|
@ -95,16 +105,19 @@ rec {
|
||||||
}
|
}
|
||||||
// (optionalAttrs (defaults ? key) { default = defaults.key; })
|
// (optionalAttrs (defaults ? key) { default = defaults.key; })
|
||||||
);
|
);
|
||||||
|
})
|
||||||
mode = mkModeOption defaults.mode or "";
|
// (optionalAttrs hasAction {
|
||||||
|
|
||||||
action = mkOption (
|
action = mkOption (
|
||||||
{
|
{
|
||||||
type = nixvimTypes.maybeRaw str;
|
type = if rawAction then nixvimTypes.maybeRaw str else str;
|
||||||
description = "The action to execute.";
|
description = "The action to execute.";
|
||||||
}
|
}
|
||||||
// (optionalAttrs (defaults ? action) { default = defaults.action; })
|
// (optionalAttrs (defaults ? action) { default = defaults.action; })
|
||||||
);
|
);
|
||||||
|
})
|
||||||
|
// {
|
||||||
|
mode = mkModeOption defaults.mode or "";
|
||||||
|
options = mapConfigOptions;
|
||||||
|
|
||||||
lua = mkOption {
|
lua = mkOption {
|
||||||
type = nullOr bool;
|
type = nullOr bool;
|
||||||
|
@ -118,8 +131,6 @@ rec {
|
||||||
default = null;
|
default = null;
|
||||||
visible = false;
|
visible = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
options = mapConfigOptions;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -36,7 +36,14 @@ in
|
||||||
keymaps = mapAttrs (
|
keymaps = mapAttrs (
|
||||||
action: defaults:
|
action: defaults:
|
||||||
helpers.mkNullOrOption (
|
helpers.mkNullOrOption (
|
||||||
with types; either str (helpers.keymaps.mkMapOptionSubmodule defaults)
|
with types;
|
||||||
|
either str (
|
||||||
|
helpers.keymaps.mkMapOptionSubmodule {
|
||||||
|
inherit defaults;
|
||||||
|
hasKey = true;
|
||||||
|
hasAction = true;
|
||||||
|
}
|
||||||
|
)
|
||||||
) "Keymap for the ${action} action."
|
) "Keymap for the ${action} action."
|
||||||
) defaultKeymaps;
|
) defaultKeymaps;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue