Skip to content

Commit

Permalink
fix: restore last cursor position for hidden buffers (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc-stripe committed Nov 2, 2022
1 parent 5218d25 commit 1f30aa2
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lua/resession/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ local function save(name, opts, target_tabpage)
name = vim.api.nvim_buf_get_name(bufnr),
loaded = vim.api.nvim_buf_is_loaded(bufnr),
options = util.save_buf_options(bufnr),
last_pos = vim.api.nvim_buf_get_mark(bufnr, '"'),
}
table.insert(data.buffers, buf)
end
Expand Down Expand Up @@ -409,13 +410,11 @@ M.load = function(name, opts)
if buf.loaded then
vim.fn.bufload(bufnr)
vim.api.nvim_create_autocmd("BufWinEnter", {
desc = "After showing the buffer in the window, manually set the filetype to trigger syntax highlighting",
callback = function()
vim.api.nvim_buf_set_option(
bufnr,
"filetype",
vim.api.nvim_buf_get_option(bufnr, "filetype")
)
desc = "Resession: complete setup of restored buffer",
callback = function(args)
pcall(vim.api.nvim_win_set_cursor, 0, buf.last_pos)
-- After showing the buffer in a window, manually set the filetype to trigger syntax highlighting
vim.api.nvim_buf_set_option(bufnr, "filetype", vim.bo[bufnr].filetype)
end,
buffer = bufnr,
once = true,
Expand Down

0 comments on commit 1f30aa2

Please sign in to comment.