(State) add track_winview()

This commit is contained in:
Jonathan Apodaca 2024-10-12 14:08:39 -06:00
parent e45d51cdf5
commit 03c5500966
2 changed files with 5 additions and 0 deletions

View File

@ -104,6 +104,7 @@ function Range.from_text_object(text_obj, opts)
local positions
vim.api.nvim_buf_call(opts.buf, function()
positions = State.run(0, function(s)
s:track_winview()
s:track_register '"'
s:track_pos '.'
s:track_pos "'["

View File

@ -5,6 +5,7 @@
---@field positions table
---@field keymaps { mode: string; lhs: any, rhs: any, buffer?: number }[]
---@field global_options table<string, any>
---@field win_view vim.fn.winsaveview.ret|nil
local State = {}
---@param buf number
@ -65,6 +66,8 @@ function State:track_pos(pos) self.positions[pos] = vim.fn.getpos(pos) end
---@param nm string
function State:track_global_option(nm) self.global_options[nm] = vim.g[nm] end
function State:track_winview() self.win_view = vim.fn.winsaveview() end
function State:restore()
for reg, val in pairs(self.registers) do
vim.fn.setreg(reg, val)
@ -81,6 +84,7 @@ function State:restore()
for nm, val in pairs(self.global_options) do
vim.g[nm] = val
end
if self.win_view ~= nil then vim.fn.winrestview(self.win_view) end
end
return State