Skip to content

Commit 29ba485

Browse files
fix: restore correct tab on load
1 parent 8fe4571 commit 29ba485

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

lua/resession/init.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ local function save(name, opts, target_tabpage)
171171
options = target_tabpage and {} or util.save_global_options(),
172172
},
173173
}
174+
local current_win = vim.api.nvim_get_current_win()
174175
local tabpage_bufs = {}
175176
if target_tabpage then
176177
for _, winid in ipairs(vim.api.nvim_tabpage_list_wins(target_tabpage)) do
@@ -201,7 +202,7 @@ local function save(name, opts, target_tabpage)
201202
tab.options = util.save_tab_options(tabpage)
202203
table.insert(data.tabs, tab)
203204
local winlayout = vim.fn.winlayout(tabnr)
204-
tab.wins = layout.add_win_info_to_layout(tabnr, winlayout)
205+
tab.wins = layout.add_win_info_to_layout(tabnr, winlayout, current_win)
205206
end
206207
vim.api.nvim_set_current_tabpage(current_tabpage)
207208

lua/resession/layout.lua

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ local M = {}
66
---@private
77
---@param tabnr integer
88
---@param winid integer
9+
---@param current_win integer
910
---@return table|false
10-
M.get_win_info = function(tabnr, winid)
11+
M.get_win_info = function(tabnr, winid, current_win)
1112
local bufnr = vim.api.nvim_win_get_buf(winid)
1213
local win = {}
1314
local supported_by_ext = false
@@ -33,7 +34,7 @@ M.get_win_info = function(tabnr, winid)
3334
end
3435
win = vim.tbl_extend("error", win, {
3536
bufname = vim.api.nvim_buf_get_name(bufnr),
36-
current = vim.api.nvim_get_current_win() == winid,
37+
current = winid == current_win,
3738
cursor = vim.api.nvim_win_get_cursor(winid),
3839
width = vim.api.nvim_win_get_width(winid),
3940
height = vim.api.nvim_win_get_height(winid),
@@ -48,18 +49,19 @@ end
4849

4950
---@param tabnr integer
5051
---@param layout table
51-
M.add_win_info_to_layout = function(tabnr, layout)
52+
---@param current_win integer
53+
M.add_win_info_to_layout = function(tabnr, layout, current_win)
5254
local type = layout[1]
5355
if type == "leaf" then
54-
layout[2] = M.get_win_info(tabnr, layout[2])
56+
layout[2] = M.get_win_info(tabnr, layout[2], current_win)
5557
if not layout[2] then
5658
return false
5759
end
5860
else
5961
local last_slot = 1
6062
local items = layout[2]
6163
for _, v in ipairs(items) do
62-
local ret = M.add_win_info_to_layout(tabnr, v)
64+
local ret = M.add_win_info_to_layout(tabnr, v, current_win)
6365
if ret then
6466
items[last_slot] = ret
6567
last_slot = last_slot + 1

0 commit comments

Comments
 (0)