fix: fixed invalid index referencing in table due to user-specified invalid mapping configuration
This commit is contained in:
parent
d3d9aa251a
commit
96d83ab549
|
@ -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
|
|
@ -53,38 +53,48 @@ end
|
||||||
|
|
||||||
M.load_mappings = function(section, mapping_opt)
|
M.load_mappings = function(section, mapping_opt)
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
local function set_section_map(section_values)
|
local function sec_section_map_func()
|
||||||
if section_values.plugin then
|
local function set_section_map(section_values)
|
||||||
return
|
if section_values.plugin then
|
||||||
end
|
return
|
||||||
|
end
|
||||||
|
|
||||||
section_values.plugin = nil
|
section_values.plugin = nil
|
||||||
|
|
||||||
for mode, mode_values in pairs(section_values) do
|
for mode, mode_values in pairs(section_values) do
|
||||||
local default_opts = merge_tb("force", { mode = mode }, mapping_opt or {})
|
local default_opts = merge_tb("force", { mode = mode }, mapping_opt or {})
|
||||||
for keybind, mapping_info in pairs(mode_values) do
|
for keybind, mapping_info in pairs(mode_values) do
|
||||||
-- merge default + user opts
|
-- merge default + user opts
|
||||||
local opts = merge_tb("force", default_opts, mapping_info.opts or {})
|
local opts = merge_tb("force", default_opts, mapping_info.opts or {})
|
||||||
|
|
||||||
mapping_info.opts, opts.mode = nil, nil
|
mapping_info.opts, opts.mode = nil, nil
|
||||||
opts.desc = mapping_info[2]
|
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
|
||||||
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
|
end
|
||||||
|
|
||||||
local mappings = require("core.utils").load_config().mappings
|
local ok, err = pcall(sec_section_map_func)
|
||||||
|
if ok == false then
|
||||||
if type(section) == "string" then
|
local chadrc_path = vim.api.nvim_get_runtime_file("lua/custom/chadrc.lua", false)[1]
|
||||||
mappings[section]["plugin"] = nil
|
error(string.format("check mappings in %s => %s", chadrc_path, err))
|
||||||
mappings = { mappings[section] }
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
for _, sect in pairs(mappings) do
|
)
|
||||||
set_section_map(sect)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
M.lazy_load = function(plugin)
|
M.lazy_load = function(plugin)
|
||||||
|
|
Loading…
Reference in New Issue