mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-30 04:14:28 +02:00
lib/keymaps: refactor mkMapOptionSubmodule
again
Allow passing in `key` and `action` as either bool or an attrset. If `false`, the option is omitted. If `true` or an attrset, the option is included. If an attrset is used, it will update the default `mkOption` args. This is useful for overriding `type` or adding an `example`.
This commit is contained in:
parent
c16533b3f7
commit
302262304e
3 changed files with 11 additions and 21 deletions
|
@ -60,11 +60,7 @@ rec {
|
|||
# ["" "n" "v" ...]
|
||||
(map ({ short, ... }: short) (attrValues modes));
|
||||
|
||||
mapOptionSubmodule = mkMapOptionSubmodule {
|
||||
hasKey = true;
|
||||
hasAction = true;
|
||||
rawAction = true;
|
||||
};
|
||||
mapOptionSubmodule = mkMapOptionSubmodule { };
|
||||
|
||||
mkModeOption =
|
||||
default:
|
||||
|
@ -85,9 +81,10 @@ rec {
|
|||
mkMapOptionSubmodule =
|
||||
{
|
||||
defaults ? { },
|
||||
hasKey ? false,
|
||||
hasAction ? false,
|
||||
rawAction ? true,
|
||||
# key and action can be true/false to enable/disable adding the option,
|
||||
# or an attrset to enable the option and add/override mkOption args.
|
||||
key ? true,
|
||||
action ? true,
|
||||
}:
|
||||
# TODO remove assert once `lua` option is gone
|
||||
# This is here to ensure no uses of `mkMapOptionSubmodule` set a `lua` default
|
||||
|
@ -96,22 +93,24 @@ rec {
|
|||
with types;
|
||||
submodule {
|
||||
options =
|
||||
(optionalAttrs hasKey {
|
||||
(optionalAttrs (isAttrs key || key) {
|
||||
key = mkOption (
|
||||
{
|
||||
type = str;
|
||||
description = "The key to map.";
|
||||
example = "<C-m>";
|
||||
}
|
||||
// (optionalAttrs (isAttrs key) key)
|
||||
// (optionalAttrs (defaults ? key) { default = defaults.key; })
|
||||
);
|
||||
})
|
||||
// (optionalAttrs hasAction {
|
||||
// (optionalAttrs (isAttrs action || action) {
|
||||
action = mkOption (
|
||||
{
|
||||
type = if rawAction then nixvimTypes.maybeRaw str else str;
|
||||
type = nixvimTypes.maybeRaw str;
|
||||
description = "The action to execute.";
|
||||
}
|
||||
// (optionalAttrs (isAttrs action) action)
|
||||
// (optionalAttrs (defaults ? action) { default = defaults.action; })
|
||||
);
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue