Windows are inserted in reverse order to what they were saved in.
This is due to the fact that a (v)split, by default, either splits to the left or top. Resession saves windows in order from left to right as vim.fn.winlayout returns them. When inserting these, the windows have to be splitted to the right or below in order to reflect the saved order.
Steps To Reproduce
Open a tab with at least 2 windows split vertically, horizontally or mixed (The loaded files should be visually easily distinguishable.
Save the session
Load the session (The windows are in the wrong order)
Expected Behavior
Splits are restored in the same order as they were saved in.
Directory structure
Any set of files is sufficient as long as they have different content, so the order is obviously visible.
Repro
-- save as repro.lua
-- run with nvim -u repro.lua
-- DO NOT change the paths
local root = vim.fn.fnamemodify("./.repro", ":p")
-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "runtime", "cache" }) do
vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end
-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"--single-branch",
"https://github.com/folke/lazy.nvim.git",
lazypath,
})
end
vim.opt.runtimepath:prepend(lazypath)
-- install plugins
local plugins = {
"folke/tokyonight.nvim",
{
"stevearc/resession.nvim",
config = function()
require("resession").setup()
end,
},
-- add any other plugins here
}
require("lazy").setup(plugins, {
root = root .. "/plugins",
})
vim.cmd.colorscheme("tokyonight")
-- add anything else here
vim.g.mapleader = " "
local resession = require('resession')
vim.keymap.set('n', '<leader>ss', resession.save)
vim.keymap.set('n', '<leader>sl', resession.load)
Did you check the bug with a clean config?
[X] I have confirmed that the bug reproduces with nvim -u repro.lua using the repro.lua file above.
Did you check the docs and existing issues?
Neovim version (nvim -v)
0.9.2
Operating system/version
MacOS 13.5.1
Describe the bug
Windows are inserted in reverse order to what they were saved in.
This is due to the fact that a
(v)split
, by default, either splits to the left or top. Resession saves windows in order from left to right asvim.fn.winlayout
returns them. When inserting these, the windows have to be splitted to the right or below in order to reflect the saved order.Steps To Reproduce
Expected Behavior
Splits are restored in the same order as they were saved in.
Directory structure
Any set of files is sufficient as long as they have different content, so the order is obviously visible.
Repro
Did you check the bug with a clean config?
nvim -u repro.lua
using the repro.lua file above.