Skip to content

Commit

Permalink
fix: restore cursor to correct position
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Sep 19, 2023
1 parent 52e556b commit d1831b3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lua/resession/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -503,10 +503,14 @@ M.load = function(name, opts)
if buf.loaded then
vim.fn.bufload(bufnr)
vim.b[bufnr]._resession_need_edit = true
vim.b[bufnr].resession_restore_last_pos = true
vim.api.nvim_create_autocmd("BufEnter", {
desc = "Resession: complete setup of restored buffer",
callback = function(args)
pcall(vim.api.nvim_win_set_cursor, 0, buf.last_pos)
if vim.b[args.buf].resession_restore_last_pos then
pcall(vim.api.nvim_win_set_cursor, 0, buf.last_pos)
vim.b[args.buf].resession_restore_last_pos = nil
end
-- This triggers the autocmds that set filetype, syntax highlighting, and checks the swapfile
if vim.b._resession_need_edit then
vim.b._resession_need_edit = nil
Expand Down
1 change: 1 addition & 0 deletions lua/resession/layout.lua
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ local function set_winlayout_data(layout, scale_factor, visit_data)
vim.o.eventignore = ""
vim.api.nvim_buf_set_option(bufnr, "filetype", vim.bo[bufnr].filetype)
vim.o.eventignore = "all"
vim.b[bufnr].resession_restore_last_pos = nil
end
pcall(vim.api.nvim_win_set_cursor, win.winid, win.cursor)
util.restore_win_options(win.winid, win.options)
Expand Down

0 comments on commit d1831b3

Please sign in to comment.