]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0793: If session restored a tiny window, restore fails v9.2.0793
authorIllia Bobyr <illia.bobyr@gmail.com>
Sat, 18 Jul 2026 13:52:22 +0000 (13:52 +0000)
committerChristian Brabandt <cb@256bit.org>
Sat, 18 Jul 2026 13:55:23 +0000 (13:55 +0000)
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.bobyr@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/session.c
src/testdir/test_mksession.vim
src/version.c

index 7c183219260ca0415eaa06472d34779db8df66ce..87019919de78839f3170ec76d1303c55c3512984 100644 (file)
@@ -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'.
index 8f35518244b314fa3ed43bff4d742f7aa73de922..179cbd32422b8cfc5285431559a4f64d5aa26fbc 100644 (file)
@@ -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
index 9118c769d828996a7f59adde05bfb0fda4236039..4e3ca0b5e791370c053ebf3e51ccedf892af2161 100644 (file)
@@ -759,6 +759,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    793,
 /**/
     792,
 /**/