patch 9.2.0793: If session restored a tiny window, restore fails
Commit:
https://github.com/vim/vim/commit/e6f47839a8a8b4790a037bfec32b784b308e4133
Author: Illia Bobyr <
illia...@gmail.com>
Date: Sat Jul 18 13:52:22 2026 +0000
patch 9.2.0793: If session restored a tiny window, restore fails
Problem: If session restored a tiny window, restore fails
Solution: Extend window sizes to be at least the minimum size during
session restore (Illia Bobyr)
If session contains a window that is shorter/narrower than the current
`&winminheight` and `&winminwidth`, respectively, Vim will fail when
assigning original values to the `&winminheight`/`&winminwidth` and the
session restore will be slightly incomplete.
It seems reasonable to assume that if the user have selected certain
values for these minimum size settings, it is safe to just make the
restored windows big enough to match the minimums and continue without
producing an error.
This fix allows `Test_mksession_winminheight()` to start with the
default values of `&winheight`/`&winwidth` and only change them after
the session restore.
closes: #20692
Supported by AI.
Signed-off-by: Illia Bobyr <
illia...@gmail.com>
Signed-off-by: Christian Brabandt <
c...@256bit.org>
diff --git a/src/session.c b/src/session.c
index 7c1832192..87019919d 100644
--- a/src/session.c
+++ b/src/session.c
@@ -975,9 +975,12 @@ makeopens(
if (put_line(fd, "endif") == FAIL)
goto fail;
- // Re-apply 'winheight' and 'winwidth'.
- if (fprintf(fd, "set winheight=%ld winwidth=%ld",
- p_wh, p_wiw) < 0 || put_eol(fd) == FAIL)
+ // Re-apply 'winheight' and 'winwidth', but honor 'winminheight' and
+ // 'winminwidth' settings we saved from the original user context.
+ if (fprintf(fd, "&winheight = max([%ld, save_winminheight])", p_wh) < 0
+ || put_eol(fd) == FAIL
+ || fprintf(fd, "&winwidth = max([%ld, save_winminwidth])", p_wiw) < 0
+ || put_eol(fd) == FAIL)
goto fail;
// Restore 'shortmess'.
diff --git a/src/testdir/test_mksession.vim b/src/testdir/test_mksession.vim
index 8f3551824..179cbd324 100644
--- a/src/testdir/test_mksession.vim
+++ b/src/testdir/test_mksession.vim
@@ -1076,8 +1076,7 @@ endfunc
" Test for mksession without options restores winminheight
func Test_mksession_winminheight()
- set winheight=10 winwidth=10 winminheight& winminwidth&
- defer execute('set winheight& winwidth&')
+ set winheight& winwidth& winminheight& winminwidth&
set sessionoptions-=options
defer execute('set sessionoptions&')
split
@@ -1097,8 +1096,8 @@ func Test_mksession_winminheight()
mksession! Xtest_mks.out
tabclose | tabclose | close
call assert_equal(1, tabpagenr('$'))
- set winminheight=2 winminwidth=2
- defer execute('set winminheight& winminwidth&')
+ set winheight=2 winminheight=2 winwidth=2 winminwidth=2
+ defer execute('set winheight& winwidth& winminheight& winminwidth&')
source Xtest_mks.out
call assert_equal(3, tabpagenr('$'))
call assert_equal([2, 2], [&winminheight, &winminwidth])
@@ -1763,4 +1762,19 @@ func Test_mksession_vim9_duplicate_import()
endfunc
+" 'winminwidth' restore must not fail when the session's saved 'winwidth' is
+" smaller than the sourcing context's 'winminwidth'.
+func Test_mksession_winminwidth()
+ set winminheight& winminwidth& winheight=2 winwidth=1 sessionoptions-=options
+ split
+ mksession! Xtest_mks.out
+ defer delete('Xtest_mks.out')
+ only
+ set winheight=2 winminheight=2 winwidth=2 winminwidth=2
+ defer execute('set winheight& winwidth& winminheight& winminwidth& sessionoptions&')
+ source Xtest_mks.out
+ call assert_equal([2, 2], [&winminheight, &winminwidth])
+ only
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index 9118c769d..4e3ca0b5e 100644
--- a/src/version.c
+++ b/src/version.c
@@ -759,6 +759,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 793,
/**/
792,
/**/