From d2dec96ad6b90ab0fdf1870b7cbfe94b319c0164 Mon Sep 17 00:00:00 2001
From: siduck <siduck@tutanota.com>
Date: Sun, 7 Aug 2022 08:50:36 +0530
Subject: [PATCH] add whichkey groups back

---
 lua/core/utils.lua               | 28 ++++++++++++++++++----------
 lua/plugins/configs/whichkey.lua | 10 ++++++++++
 2 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/lua/core/utils.lua b/lua/core/utils.lua
index 6d174df..bb986ab 100644
--- a/lua/core/utils.lua
+++ b/lua/core/utils.lua
@@ -15,10 +15,27 @@ M.close_buffer = function(bufnr)
   end
 end
 
+-- store mapping section names which have plugin key = true
+local lazyload_mappings_list = {}
+
+local add_mappingSection_toList = function()
+  local default_mappings = require("core.default_config").mappings
+
+  -- store mapping section name into a table
+  for section_name, section_mappings in pairs(default_mappings) do
+    if section_mappings.plugin then
+      lazyload_mappings_list[section_name] = true
+      section_mappings.plugin = nil
+    end
+  end
+end
+
 M.load_config = function()
   local config = require "core.default_config"
   local chadrc_exists, chadrc = pcall(require, "custom.chadrc")
 
+  add_mappingSection_toList()
+
   if chadrc_exists then
     -- merge user config if it exists and is a table; otherwise display an error
     if type(chadrc) == "table" then
@@ -33,9 +50,6 @@ M.load_config = function()
   return config
 end
 
--- store mapping section names which have plugin key = true
-local lazyload_mappings_list = {}
-
 M.remove_default_keys = function(user_mappings)
   local user_keys = {}
   local user_sections = vim.tbl_keys(user_mappings)
@@ -54,13 +68,7 @@ M.remove_default_keys = function(user_mappings)
   local default_mappings = require("core.default_config").mappings
 
   -- remove user_maps from default mapping table
-  for section_name, section_mappings in pairs(default_mappings) do
-    -- store mapping section name into a table
-    if section_mappings.plugin then
-      lazyload_mappings_list[section_name] = true
-      section_mappings.plugin = nil
-    end
-
+  for _, section_mappings in pairs(default_mappings) do
     for mode, mode_mapping in pairs(section_mappings) do
       for keybind, _ in pairs(mode_mapping) do
         disable_key(mode, keybind, mode_mapping)
diff --git a/lua/plugins/configs/whichkey.lua b/lua/plugins/configs/whichkey.lua
index 89e7c3e..7bc8ef4 100644
--- a/lua/plugins/configs/whichkey.lua
+++ b/lua/plugins/configs/whichkey.lua
@@ -38,4 +38,14 @@ local options = {
 
 options = require("core.utils").load_override(options, "folke/which-key.nvim")
 
+local utils = require "core.utils"
+
+local mappings = utils.load_config().mappings
+local mapping_groups = { groups = vim.deepcopy(mappings.groups) }
+
+mappings.disabled = nil
+mappings.groups = nil
+
+utils.load_mappings(mapping_groups)
+
 wk.setup(options)