Skip to content

Commit

Permalink
fix(ui): save/restore view right before/after rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jun 29, 2024
1 parent a75d950 commit 5d334b9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 0 additions & 6 deletions lua/lazy/view/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,7 @@ end

function M:update()
if self.buf and vim.api.nvim_buf_is_valid(self.buf) then
vim.bo[self.buf].modifiable = true
local view = vim.api.nvim_win_call(self.view.win, vim.fn.winsaveview)
self.render:update()
vim.api.nvim_win_call(self.view.win, function()
vim.fn.winrestview(view)
end)
vim.bo[self.buf].modifiable = false
vim.cmd.redraw()
end
end
Expand Down
10 changes: 10 additions & 0 deletions lua/lazy/view/render.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,17 @@ function M:update()
end

self:trim()

vim.bo[self.view.buf].modifiable = true
local view = vim.api.nvim_win_call(self.view.win, vim.fn.winsaveview)

self:render(self.view.buf)

vim.api.nvim_win_call(self.view.win, function()
vim.fn.winrestview(view)
end)
vim.bo[self.view.buf].modifiable = false

vim.diagnostic.set(
Config.ns,
self.view.buf,
Expand Down

0 comments on commit 5d334b9

Please sign in to comment.