Skip to content

Commit c57ff6f

Browse files
fix: save cmdheight per-tabpage (#7)
1 parent 6bda7fd commit c57ff6f

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

lua/resession/init.lua

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,17 +187,21 @@ local function save(name, opts, target_tabpage)
187187
table.insert(data.buffers, buf)
188188
end
189189
end
190+
local current_tabpage = vim.api.nvim_get_current_tabpage()
190191
local tabpages = target_tabpage and { target_tabpage } or vim.api.nvim_list_tabpages()
191192
for _, tabpage in ipairs(tabpages) do
193+
vim.api.nvim_set_current_tabpage(tabpage)
192194
local tab = {}
193195
local tabnr = vim.api.nvim_tabpage_get_number(tabpage)
194196
if target_tabpage or vim.fn.haslocaldir(-1, tabnr) == 1 then
195197
tab.cwd = vim.fn.getcwd(-1, tabnr)
196198
end
199+
tab.options = util.save_tab_options(tabpage)
197200
table.insert(data.tabs, tab)
198201
local winlayout = vim.fn.winlayout(tabnr)
199202
tab.wins = layout.add_win_info_to_layout(tabnr, winlayout)
200203
end
204+
vim.api.nvim_set_current_tabpage(current_tabpage)
201205

202206
for ext_name, ext_config in pairs(config.extensions) do
203207
local ext = util.get_extension(ext_name)
@@ -461,6 +465,9 @@ M.load = function(name, opts)
461465
if win then
462466
curwin = win
463467
end
468+
if tab.options then
469+
util.restore_tab_options(tab.options)
470+
end
464471
end
465472
-- This can be nil if we saved a session in a window with an unsupported buffer
466473
if curwin then
@@ -482,10 +489,6 @@ M.load = function(name, opts)
482489
end
483490
end
484491

485-
-- We re-apply the options because sometimes the cmdheight gets messed up for some reason
486-
for k, v in pairs(data.global.options) do
487-
vim.o[k] = v
488-
end
489492
current_session = nil
490493
if opts.reset then
491494
tab_sessions = {}

lua/resession/util.lua

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ M.save_buf_options = function(bufnr)
5050
return ret
5151
end
5252

53+
---@param bufnr integer
54+
---@return table<string, any>
55+
M.save_tab_options = function(bufnr)
56+
local ret = {}
57+
-- 'cmdheight' is the only tab-local option, but the scope from nvim_get_option_info is incorrect
58+
-- since there's no way to fetch a tabpage-local option, we rely on this being called from inside
59+
-- the relevant tabpage
60+
if vim.tbl_contains(config.options, "cmdheight") then
61+
ret.cmdheight = vim.o.cmdheight
62+
end
63+
return ret
64+
end
65+
5366
---@param opts table<string, any>
5467
M.restore_global_options = function(opts)
5568
for opt, val in pairs(opts) do
@@ -82,6 +95,15 @@ M.restore_buf_options = function(bufnr, opts)
8295
end
8396
end
8497

98+
---@param opts table<string, any>
99+
M.restore_tab_options = function(opts)
100+
-- 'cmdheight' is the only tab-local option. See save_tab_options
101+
if opts.cmdheight then
102+
-- empirically, this seems to only set the local tab value
103+
vim.o.cmdheight = opts.cmdheight
104+
end
105+
end
106+
85107
---@param dirname? string
86108
---@return string
87109
M.get_session_dir = function(dirname)

0 commit comments

Comments
 (0)