lib/keymap: allow extra options/modules in mkMapOptionSubmodule

This is needed to allow plugins to add bespoke features to their keymap
submodules without having to re-implement the whole thing.
This commit is contained in:
Matt Sturgeon 2024-08-18 21:27:48 +01:00
parent 7fb1f9dd9d
commit 7a11b66f11
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299

View file

@ -82,17 +82,26 @@ rec {
mkMapOptionSubmodule = mkMapOptionSubmodule =
{ {
# Allow overriding defaults for key, action, mode, etc
defaults ? { }, defaults ? { },
# key and action can be true/false to enable/disable adding the option, # 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. # or an attrset to enable the option and add/override mkOption args.
key ? true, key ? true,
action ? true, action ? true,
lua ? false, # WARNING: for historic use only - do not use in new options! lua ? false, # WARNING: for historic use only - do not use in new options!
# Allow passing additional options or modules to the submodule
# Useful for plugin-specific features
extraOptions ? { },
extraModules ? [ ],
}: }:
with types; with types;
submodule ( submodule (
{ config, options, ... }: { config, options, ... }:
{ {
imports = extraModules;
options = options =
(optionalAttrs (isAttrs key || key) { (optionalAttrs (isAttrs key || key) {
key = mkOption ( key = mkOption (
@ -135,7 +144,8 @@ rec {
// { // {
mode = mkModeOption defaults.mode or ""; mode = mkModeOption defaults.mode or "";
options = mapConfigOptions; options = mapConfigOptions;
}; }
// extraOptions;
} }
); );