]> granicus.if.org Git - vim/commitdiff
patch 8.2.2447: 'foldlevel' not applied to folds restored from session v8.2.2447
authorBram Moolenaar <Bram@vim.org>
Mon, 1 Feb 2021 18:24:55 +0000 (19:24 +0100)
committerBram Moolenaar <Bram@vim.org>
Mon, 1 Feb 2021 18:24:55 +0000 (19:24 +0100)
Problem:    'foldlevel' not applied to folds restored from session.
Solution:   Set 'foldlevel' after creaiting the folds. (closes #7767)

src/fold.c
src/testdir/test_mksession.vim
src/version.c

index f889f4c74da150a61351747157a3820cd551f13f..75b436a67e05f997352500bb73153ba7157c4752 100644 (file)
@@ -3309,7 +3309,7 @@ foldlevelExpr(fline_T *flp)
     // KeyTyped may be reset to 0 when calling a function which invokes
     // do_cmdline().  To make 'foldopen' work correctly restore KeyTyped.
     save_keytyped = KeyTyped;
-    n = (int)eval_foldexpr(flp->wp->w_p_fde, &c);
+    n = eval_foldexpr(flp->wp->w_p_fde, &c);
     KeyTyped = save_keytyped;
 
     switch (c)
@@ -3526,7 +3526,8 @@ put_folds(FILE *fd, win_T *wp)
     if (foldmethodIsManual(wp))
     {
        if (put_line(fd, "silent! normal! zE") == FAIL
-               || put_folds_recurse(fd, &wp->w_folds, (linenr_T)0) == FAIL)
+               || put_folds_recurse(fd, &wp->w_folds, (linenr_T)0) == FAIL
+               || put_line(fd, "let &fdl = &fdl") == FAIL)
            return FAIL;
     }
 
index 723eb8ed2db3e959ce8b7718e2beb1876756b8d3..82c96ce6396a836cd8a6c80c821de13f92420f67 100644 (file)
@@ -504,6 +504,32 @@ func Test_mkview_terminal_windows()
   call delete('Xtestview')
 endfunc
 
+func Test_mkview_open_folds()
+  enew!
+
+  call append(0, ['a', 'b', 'c'])
+  1,3fold
+  " zR affects 'foldlevel', make sure the option is applied after the folds
+  " have been recreated.
+  normal zR
+  write! Xtestfile
+
+  call assert_equal(-1, foldclosed(1))
+  call assert_equal(-1, foldclosed(2))
+  call assert_equal(-1, foldclosed(3))
+
+  mkview! Xtestview
+  source Xtestview
+
+  call assert_equal(-1, foldclosed(1))
+  call assert_equal(-1, foldclosed(2))
+  call assert_equal(-1, foldclosed(3))
+
+  call delete('Xtestview')
+  call delete('Xtestfile')
+  %bwipe
+endfunc
+
 " Test :mkview with a file argument.
 func Test_mkview_file()
   " Create a view with line number and a fold.
index bba9da818f791527db9b99bff4e6d9960c3255ce..61acfadd4624379520ec17f6b027dfd9f5b7004b 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2447,
 /**/
     2446,
 /**/