Skip to content

Commit

Permalink
fix: restore win view after rendering buffer (#516)
Browse files Browse the repository at this point in the history
problem: as of neovim/neovim#24824 buf_set_lines adjusts topline differently, which breaks scrolling in the which-key menu.
solution: save and restore view when rendering to ensure that the render does not change scroll position.

fixes #515
  • Loading branch information
willothy committed Jun 6, 2024
1 parent f5b9124 commit ea4a17d
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lua/which-key/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ end

---@param text Text
function M.render(text)
local view = vim.api.nvim_win_call(M.win, vim.fn.winsaveview)
vim.api.nvim_buf_set_lines(M.buf, 0, -1, false, text.lines)
local height = #text.lines
if height > config.options.layout.height.max then
Expand All @@ -340,6 +341,9 @@ function M.render(text)
for _, data in ipairs(text.hl) do
highlight(M.buf, config.namespace, data.group, data.line, data.from, data.to)
end
vim.api.nvim_win_call(M.win, function()
vim.fn.winrestview(view)
end)
end

return M

0 comments on commit ea4a17d

Please sign in to comment.