Skip to content

Commit

Permalink
restore view after format
Browse files Browse the repository at this point in the history
  • Loading branch information
glepnir committed Jul 20, 2023
1 parent 72a89f0 commit 59c1082
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lua/guard/format.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ local function update_buffer(bufnr, new_lines, srow, erow)
if not new_lines or #new_lines == 0 then
return
end
local view = vim.fn.winsaveview()

local prev_lines = vim.api.nvim_buf_get_lines(bufnr, srow, erow, true)
new_lines = vim.split(new_lines, '\n')
Expand Down Expand Up @@ -61,6 +62,7 @@ local function update_buffer(bufnr, new_lines, srow, erow)
if mode == 'v' or 'V' then
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Esc>', true, false, true), 'n', true)
end
vim.fn.winrestview(view)
end

local function do_fmt(buf)
Expand Down

0 comments on commit 59c1082

Please sign in to comment.