diff --git a/plugins/utils/which-key.nix b/plugins/utils/which-key.nix index 80d6654b..69613d5e 100644 --- a/plugins/utils/which-key.nix +++ b/plugins/utils/which-key.nix @@ -11,6 +11,68 @@ let types = lib.nixvim.nixvimTypes; opt = options.plugins.which-key; + + specExamples = [ + # Basic group + { + __unkeyed-1 = "b"; + group = "󰓩 Buffers"; + } + # Non-default mode + { + __unkeyed = "c"; + mode = "v"; + group = "󰄄 Codesnap"; + } + # Group within group + { + __unkeyed-1 = "bs"; + group = "󰒺 Sort"; + } + # Nested mappings for inheritance + { + mode = [ + "n" + "v" + ]; + __unkeyed-1 = [ + { + __unkeyed-1 = "f"; + group = "Normal Visual Group"; + } + { + __unkeyed-1 = "f"; + group = "Normal Visual Group in Group"; + } + ]; + } + # Proxy mapping + { + __unkeyed-1 = "w"; + proxy = ""; + group = "windows"; + } + # Create mapping + { + __unkeyed-1 = "cS"; + __unkeyed-2 = "CodeSnapSave"; + mode = "v"; + desc = "Save"; + } + # Function mapping + { + __unkeyed-1 = "db"; + __unkeyed-2.__raw = '' + function() + require("dap").toggle_breakpoint() + end + ''; + mode = "n"; + desc = "Breakpoint toggle"; + silent = true; + } + ]; + in lib.nixvim.neovim-plugin.mkNeovimPlugin config { name = "which-key"; @@ -246,22 +308,7 @@ lib.nixvim.neovim-plugin.mkNeovimPlugin config { Please refer to the plugin's [documentation](https://github.com/folke/which-key.nvim?tab=readme-ov-file#%EF%B8%8F-mappings). ''; - example = [ - { - __unkeyed-1 = "w"; - proxy = ""; - group = "windows"; - } - { - __unkeyed-1 = "b"; - group = "󰓩 Buffers"; - } - { - __unkeyed = "r"; - mode = "x"; - group = " Refactor"; - } - ]; + example = specExamples; }; notify = defaultNullOpts.mkBool true "Show a warning when issues were detected with your mappings."; @@ -483,36 +530,7 @@ lib.nixvim.neovim-plugin.mkNeovimPlugin config { delay = 200; - spec = [ - { - __unkeyed-1 = "b"; - group = "󰓩 Buffers"; - } - { - __unkeyed-1 = "bs"; - group = "󰒺 Sort"; - } - { - __unkeyed-1 = "g"; - group = "󰊢 Git"; - } - { - __unkeyed-1 = "f"; - group = " Find"; - } - { - __unkeyed-1 = "r"; - group = " Refactor"; - } - { - __unkeyed-1 = "t"; - group = " Terminal"; - } - { - __unkeyed-1 = "u"; - group = " UI/UX"; - } - ]; + spec = specExamples; replace = { desc = [ diff --git a/tests/test-sources/plugins/utils/which-key.nix b/tests/test-sources/plugins/utils/which-key.nix index d03ae072..f1adefb6 100644 --- a/tests/test-sources/plugins/utils/which-key.nix +++ b/tests/test-sources/plugins/utils/which-key.nix @@ -251,6 +251,42 @@ desc = "Vim cmd KeyMapping Test"; inherit mode; } + # Nested mapping + { + mode = [ + "n" + "v" + ]; + __unkeyed-1 = [ + { + __unkeyed-1 = "f"; + group = "Group Test"; + } + { + __unkeyed-1 = "f"; + group = "Group in Group Test"; + } + ]; + } + # Create mapping + { + __unkeyed-1 = "cS"; + __unkeyed-2 = "CodeSnapSave"; + mode = "v"; + desc = "Save"; + } + # Function mapping + { + __unkeyed-1 = "db"; + __unkeyed-2.__raw = '' + function() + require("dap").toggle_breakpoint() + end + ''; + mode = "n"; + desc = "Breakpoint toggle"; + silent = true; + } ]; }; };