fix: fixed invalid index referencing in table due to user-specified invalid mapping configuration

This commit is contained in:
Salih Bozkaya 2023-08-19 14:20:10 +03:00
parent d3d9aa251a
commit 96d83ab549
2 changed files with 53 additions and 23 deletions

20
] Normal file
View File

@ -0,0 +1,20 @@
---@type ChadrcConfig
local M = {}
-- Path to overriding theme and highlights files
local highlights = require "custom.highlights"
M.ui = {
theme = "jellybeans",
-- theme_toggle = { "onedark", "one_light" },
hl_override = highlights.override,
hl_add = highlights.add,
}
M.plugins = "custom.plugins"
-- check core.mappings for table structure
M.mappings = require "custom.mappings"
return M

View File

@ -53,38 +53,48 @@ end
M.load_mappings = function(section, mapping_opt)
vim.schedule(function()
local function set_section_map(section_values)
if section_values.plugin then
return
end
local function sec_section_map_func()
local function set_section_map(section_values)
if section_values.plugin then
return
end
section_values.plugin = nil
section_values.plugin = nil
for mode, mode_values in pairs(section_values) do
local default_opts = merge_tb("force", { mode = mode }, mapping_opt or {})
for keybind, mapping_info in pairs(mode_values) do
-- merge default + user opts
local opts = merge_tb("force", default_opts, mapping_info.opts or {})
for mode, mode_values in pairs(section_values) do
local default_opts = merge_tb("force", { mode = mode }, mapping_opt or {})
for keybind, mapping_info in pairs(mode_values) do
-- merge default + user opts
local opts = merge_tb("force", default_opts, mapping_info.opts or {})
mapping_info.opts, opts.mode = nil, nil
opts.desc = mapping_info[2]
mapping_info.opts, opts.mode = nil, nil
opts.desc = mapping_info[2]
vim.keymap.set(mode, keybind, mapping_info[1], opts)
vim.keymap.set(mode, keybind, mapping_info[1], opts)
end
end
end
local mappings = require("core.utils").load_config().mappings
if type(section) == "string" then
mappings[section]["plugin"] = nil
mappings = { mappings[section] }
end
for _, sect in pairs(mappings) do
set_section_map(sect)
end
end
local mappings = require("core.utils").load_config().mappings
if type(section) == "string" then
mappings[section]["plugin"] = nil
mappings = { mappings[section] }
local ok, err = pcall(sec_section_map_func)
if ok == false then
local chadrc_path = vim.api.nvim_get_runtime_file("lua/custom/chadrc.lua", false)[1]
error(string.format("check mappings in %s => %s", chadrc_path, err))
end
for _, sect in pairs(mappings) do
set_section_map(sect)
end
end)
end
)
end
M.lazy_load = function(plugin)