Skip to content

Commit

Permalink
feat: manual sorting. Closes #131, Closes #362, Closes #264
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jul 12, 2024
1 parent 528fc43 commit c2daf9d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lua/which-key/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ local defaults = {
scroll_up = "<c-u>", -- binding to scroll up inside the popup
},
---@type (string|wk.Sorter)[]
--- Add "manual" as the first element to use the order the mappings were registered
sort = { "order", "group", "alphanum", "mod", "lower", "icase" },
expand = 1, -- expand groups when <= n mappings
---@type table<string, ({[1]:string, [2]:string}|fun(str:string):string)[]>
replace = {
key = {
Expand Down Expand Up @@ -149,16 +151,15 @@ end

function M.register(mappings, opts)
local Mappings = require("which-key.mappings")
local ret = {} ---@type wk.Keymap[]
for _, km in ipairs(Mappings.parse(mappings, opts)) do
if km.rhs or km.callback then
vim.keymap.set(km.mode, km.lhs, km.callback or km.rhs or "", Mappings.opts(km))
else
km.virtual = true
ret[#ret + 1] = km
table.insert(M.mappings, km)
km.idx = #M.mappings
end
end
vim.list_extend(M.mappings, ret)
if M.loaded then
require("which-key.buf").reset()
end
Expand Down
1 change: 1 addition & 0 deletions lua/which-key/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

---@class wk.Keymap: vim.api.keyset.keymap
---@field lhs string
---@field idx? number
---@field mode string
---@field rhs? string
---@field lhsraw? string
Expand Down
3 changes: 3 additions & 0 deletions lua/which-key/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ M.fields = {
order = function(item)
return item.order and item.order or 1000
end,
manual = function(item)
return item.virtual and item.virtual.idx or 10000
end,
desc = function(item)
return item.desc or "~"
end,
Expand Down

0 comments on commit c2daf9d

Please sign in to comment.