]> granicus.if.org Git - vim/commitdiff
patch 9.0.1213: adding a line below the last one does not expand fold v9.0.1213
authorBrandon Simmons <simmsbra@gmail.com>
Tue, 17 Jan 2023 19:48:07 +0000 (19:48 +0000)
committerBram Moolenaar <Bram@vim.org>
Tue, 17 Jan 2023 19:48:07 +0000 (19:48 +0000)
Problem:    Adding a line below the last one does not expand fold.
Solution:   Do not skip mark_adjust() when adding lines below the last one.
            (Brandon Simmons, closes #11832, closes #10698)

src/change.c
src/register.c
src/testdir/test_fold.vim
src/version.c

index dc68d3cf7c0ba97b8b4f81cf2bdfec500c0a0a83..1e7bdd6bdb9cd6d35b5115096a3a31b2bc04158e 100644 (file)
@@ -772,14 +772,7 @@ appended_lines(linenr_T lnum, long count)
     void
 appended_lines_mark(linenr_T lnum, long count)
 {
-    // Skip mark_adjust when adding a line after the last one, there can't
-    // be marks there. But it's still needed in diff mode.
-    if (lnum + count < curbuf->b_ml.ml_line_count
-#ifdef FEAT_DIFF
-           || curwin->w_p_diff
-#endif
-       )
-       mark_adjust(lnum + 1, (linenr_T)MAXLNUM, count, 0L);
+    mark_adjust(lnum + 1, (linenr_T)MAXLNUM, count, 0L);
     changed_lines(lnum + 1, 0, lnum + 1, count);
 }
 
@@ -2142,14 +2135,7 @@ open_line(
            goto theend;
        // Postpone calling changed_lines(), because it would mess up folding
        // with markers.
-       // Skip mark_adjust when adding a line after the last one, there can't
-       // be marks there. But still needed in diff mode.
-       if (curwin->w_cursor.lnum + 1 < curbuf->b_ml.ml_line_count
-#ifdef FEAT_DIFF
-               || curwin->w_p_diff
-#endif
-           )
-           mark_adjust(curwin->w_cursor.lnum + 1, (linenr_T)MAXLNUM, 1L, 0L);
+       mark_adjust(curwin->w_cursor.lnum + 1, (linenr_T)MAXLNUM, 1L, 0L);
        did_append = TRUE;
 #ifdef FEAT_PROP_POPUP
        if ((State & MODE_INSERT) && (State & VREPLACE_FLAG) == 0)
index bc687c0b13e495b32d1c5865c3dced23faafbb24..3454cfaa610f72962280a850773e0d73bf886793 100644 (file)
@@ -2208,15 +2208,7 @@ error:
                if (dir == FORWARD)
                    curbuf->b_op_start.lnum++;
            }
-           // Skip mark_adjust when adding lines after the last one, there
-           // can't be marks there. But still needed in diff mode.
-           if (curbuf->b_op_start.lnum + (y_type == MCHAR) - 1 + nr_lines
-                                                < curbuf->b_ml.ml_line_count
-#ifdef FEAT_DIFF
-                                                || curwin->w_p_diff
-#endif
-                                                )
-               mark_adjust(curbuf->b_op_start.lnum + (y_type == MCHAR),
+           mark_adjust(curbuf->b_op_start.lnum + (y_type == MCHAR),
                                             (linenr_T)MAXLNUM, nr_lines, 0L);
 
            // note changed text for displaying and folding
index f915a661336b4998d62fc6ee40c5e0bfb1ddf467..7f75e91975f6da88c0a151b44c15632fc0dcf7f5 100644 (file)
@@ -1683,4 +1683,17 @@ func Test_indent_with_L_command()
   bwipe!
 endfunc
 
+" Make sure that when there is a fold at the bottom of the buffer and a newline
+" character is appended to the line, the fold gets expanded (instead of the new
+" line not being part of the fold).
+func Test_expand_fold_at_bottom_of_buffer()
+  new
+  " create a fold on the only line
+  fold
+  execute "normal A\<CR>"
+  call assert_equal([1, 1], range(1, 2)->map('foldlevel(v:val)'))
+
+  bwipe!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 3496b3af8927849773c9e4e7c1620bb5a521493b..ae5de35192fb785ee69c001bca5248e295af3cde 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1213,
 /**/
     1212,
 /**/