Skip to content

Commit

Permalink
view/render: Merge keybindings
Browse files Browse the repository at this point in the history
in lazy overview when a common prefix exists.
  • Loading branch information
har7an committed Feb 19, 2024
1 parent aedcd79 commit 0e6ce41
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions lua/lazy/view/render.lua
Original file line number Diff line number Diff line change
Expand Up @@ -546,10 +546,25 @@ function M:handlers(plugin, types)
types = type(types) == "string" and { types } or types
types = types and types or vim.tbl_keys(Handler.types)
for _, t in ipairs(types) do
for id, value in pairs(plugin._.handlers[t] or {}) do
value = t == "keys" and Keys.to_string(value) or id
self:reason({ [t] = value })
self:append(" ")
items = plugin._.handlers[t] or {}
if t == "keys" then
local last_key_val = nil
for id, value in vim.spairs(items) do
value = Keys.to_string(value) or id
local value_pat = vim.pesc(value)
if last_key_val and string.find(value_pat, "^" .. last_key_val) then
-- matches previous, shorter prefix - pass
else
self:reason({ [t] = value })
self:append(" ")
last_key_val = value_pat
end
end
else
for _, value in pairs(items) do
self:reason({ [t] = value })
self:append(" ")
end
end
end
end
Expand Down

0 comments on commit 0e6ce41

Please sign in to comment.