Skip to content

Commit

Permalink
fix(ui): make sure the which-key window never overlaps the user's cur…
Browse files Browse the repository at this point in the history
…sor position
  • Loading branch information
folke committed Jul 11, 2024
1 parent 7b617b2 commit ad18d01
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions lua/which-key/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ local defaults = {
},
---@type (string|wk.Sorter)[]
--- Add "manual" as the first element to use the order the mappings were registered
--- Other sorters: "desc"
sort = { "local", "order", "group", "alphanum", "mod", "lower", "icase" },
expand = 1, -- expand groups when <= n mappings
---@type table<string, ({[1]:string, [2]:string}|fun(str:string):string)[]>
Expand Down
8 changes: 8 additions & 0 deletions lua/which-key/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -383,14 +383,22 @@ function M.show()

opts.width = M.dim(opts.width, vim.o.columns, text:width() + bw)
opts.height = M.dim(opts.height, vim.o.lines, text:height() + bw)

if Config.show_help then
opts.height = opts.height + 1
end

-- top-left
opts.col = Layout.dim(opts.col, { parent = vim.o.columns })
opts.row = opts.row < 0 and vim.o.lines + opts.row - opts.height or opts.row
opts.width = opts.width - bw
opts.height = opts.height - bw
local cursor = vim.fn.screenrow()
if cursor >= opts.row and cursor <= opts.row + opts.height then
opts.row = cursor + 1
end
opts.height = math.max(vim.o.lines - opts.row, 1)

M.mount(opts)

if Config.show_help or show_keys then
Expand Down

0 comments on commit ad18d01

Please sign in to comment.