diff --git a/lua/gitlinker.lua b/lua/gitlinker.lua index 8e68bc0..2ca4072 100644 --- a/lua/gitlinker.lua +++ b/lua/gitlinker.lua @@ -415,20 +415,33 @@ end --- @return table local function _merge_routers(opts) local result = {} - -- default routers - -- default_router_type: browse, blame, etc + + -- users list + if type(opts.router) == "table" then + -- user_router_type: browse, blame, etc + for user_router_type, user_router_bindings in pairs(opts.router) do + if result[user_router_type] == nil then + result[user_router_type] = {} + result[user_router_type].list_routers = {} + result[user_router_type].map_routers = {} + end + -- list + for i, tuple in ipairs(user_router_bindings) do + if type(i) == "number" and type(tuple) == "table" and #tuple == 2 then + -- prepend to head for higher priority + table.insert(result[user_router_type].list_routers, 1, tuple) + end + end + end + end + + -- default map for default_router_type, default_router_bindings in pairs(Defaults.router) do if result[default_router_type] == nil then result[default_router_type] = {} result[default_router_type].list_routers = {} result[default_router_type].map_routers = {} end - -- list - for i, tuple in ipairs(default_router_bindings) do - if type(i) == "number" and type(tuple) == "table" and #tuple == 2 then - table.insert(result[default_router_type].list_routers, tuple) - end - end -- map for pattern, route in pairs(default_router_bindings) do if result[default_router_type].map_routers == nil then @@ -443,21 +456,20 @@ local function _merge_routers(opts) end end end + + -- default list + for default_router_type, default_router_bindings in pairs(Defaults.router) do + -- list + for i, tuple in ipairs(default_router_bindings) do + if type(i) == "number" and type(tuple) == "table" and #tuple == 2 then + table.insert(result[default_router_type].list_routers, tuple) + end + end + end + + -- user map if type(opts.router) == "table" then - -- user_router_type: browse, blame, etc for user_router_type, user_router_bindings in pairs(opts.router) do - if result[user_router_type] == nil then - result[user_router_type] = {} - result[user_router_type].list_routers = {} - result[user_router_type].map_routers = {} - end - -- list - for i, tuple in ipairs(user_router_bindings) do - if type(i) == "number" and type(tuple) == "table" and #tuple == 2 then - -- prepend to head for higher priority - table.insert(result[user_router_type].list_routers, 1, tuple) - end - end -- map for pattern, route in pairs(user_router_bindings) do if result[user_router_type].map_routers == nil then