fix: which-key group names can now be properly set with M.groups & refactoring

This commit is contained in:
Leon Heidelbach 2022-05-16 14:31:47 +02:00 committed by siduck
parent ec62a5cee8
commit 5716bbcca0
2 changed files with 21 additions and 15 deletions

View File

@ -60,12 +60,13 @@ end
-- remove disabled mappings from a given key map -- remove disabled mappings from a given key map
nvchad.remove_disabled_mappings = function(key_map) nvchad.remove_disabled_mappings = function(key_map)
local clean_map = {} local clean_map = {}
if key_map == nil or key_map == "" then
return key_map
end
if type(key_map) == "table" then if type(key_map) == "table" then
for k, v in pairs(key_map) do for k, v in pairs(key_map) do
if v ~= nil and v ~= "" then clean_map[k] = v end if v ~= nil and v ~= "" then clean_map[k] = v end
end end
elseif not key_map == nil and not key_map == "" then
return key_map
end end
return clean_map return clean_map
end end
@ -80,17 +81,14 @@ nvchad.prune_key_map = function(key_map, prune_map, ignore_modes)
for ext, modes in pairs(key_map) do for ext, modes in pairs(key_map) do
for mode, mappings in pairs(modes) do for mode, mappings in pairs(modes) do
if not vim.tbl_contains(ignore_modes, mode) then if not vim.tbl_contains(ignore_modes, mode) then
if prune_keys[mode] then
-- filter mappings table so that only keys that are not in user_mappings are left -- filter mappings table so that only keys that are not in user_mappings are left
local filtered_mappings = {} for b, _ in pairs(mappings) do
for k, v in pairs(mappings) do if prune_keys[mode] and vim.tbl_contains(prune_keys[mode], b) then
if not vim.tbl_contains(prune_keys[mode], k) then key_map[ext][mode][b] = nil
filtered_mappings[k] = nvchad.remove_disabled_mappings(v)
end end
end end
key_map[ext][mode] = filtered_mappings
end
end end
key_map[ext][mode] = nvchad.remove_disabled_mappings(mappings)
end end
end end

View File

@ -58,17 +58,25 @@ local options = {
require("plugins.configs.others").misc_mappings() require("plugins.configs.others").misc_mappings()
local mappings = nvchad.load_config().mappings local mappings = nvchad.load_config().mappings
local mapping_groups = { groups = vim.deepcopy(mappings.groups) }
mappings.disabled = nil
mappings.groups = nil
-- register mappings -- register mappings
for mode, opt in pairs(options.mode_opts) do local function register_mappings(maps, opts)
for _, value in pairs(mappings) do for mode, opt in pairs(opts.mode_opts) do
for _, value in pairs(maps) do
if value[mode] then if value[mode] then
local mode_opts = value["mode_opts"] and vim.tbl_deep_extend("force", opt, value["mode_opts"]) or opt local mode_opts = value["mode_opts"] and vim.tbl_deep_extend("force", opt, value["mode_opts"]) or opt
wk.register(value[mode], mode_opts) wk.register(value[mode], mode_opts)
end end
end end
end
end end
register_mappings(mappings, options)
register_mappings(mapping_groups, options)
options = nvchad.load_override(options, "folke/which-key.nvim") options = nvchad.load_override(options, "folke/which-key.nvim")
wk.setup(options) wk.setup(options)