Skip to content

Commit da3dd7d

Browse files
simmsbrabrammool
authored andcommitted
patch 9.0.1213: adding a line below the last one does not expand fold
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)
1 parent 66bb9ae commit da3dd7d

4 files changed

Lines changed: 18 additions & 25 deletions

File tree

src/change.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -772,14 +772,7 @@ appended_lines(linenr_T lnum, long count)
772772
void
773773
appended_lines_mark(linenr_T lnum, long count)
774774
{
775-
// Skip mark_adjust when adding a line after the last one, there can't
776-
// be marks there. But it's still needed in diff mode.
777-
if (lnum + count < curbuf->b_ml.ml_line_count
778-
#ifdef FEAT_DIFF
779-
|| curwin->w_p_diff
780-
#endif
781-
)
782-
mark_adjust(lnum + 1, (linenr_T)MAXLNUM, count, 0L);
775+
mark_adjust(lnum + 1, (linenr_T)MAXLNUM, count, 0L);
783776
changed_lines(lnum + 1, 0, lnum + 1, count);
784777
}
785778

@@ -2142,14 +2135,7 @@ open_line(
21422135
goto theend;
21432136
// Postpone calling changed_lines(), because it would mess up folding
21442137
// with markers.
2145-
// Skip mark_adjust when adding a line after the last one, there can't
2146-
// be marks there. But still needed in diff mode.
2147-
if (curwin->w_cursor.lnum + 1 < curbuf->b_ml.ml_line_count
2148-
#ifdef FEAT_DIFF
2149-
|| curwin->w_p_diff
2150-
#endif
2151-
)
2152-
mark_adjust(curwin->w_cursor.lnum + 1, (linenr_T)MAXLNUM, 1L, 0L);
2138+
mark_adjust(curwin->w_cursor.lnum + 1, (linenr_T)MAXLNUM, 1L, 0L);
21532139
did_append = TRUE;
21542140
#ifdef FEAT_PROP_POPUP
21552141
if ((State & MODE_INSERT) && (State & VREPLACE_FLAG) == 0)

src/register.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2208,15 +2208,7 @@ do_put(
22082208
if (dir == FORWARD)
22092209
curbuf->b_op_start.lnum++;
22102210
}
2211-
// Skip mark_adjust when adding lines after the last one, there
2212-
// can't be marks there. But still needed in diff mode.
2213-
if (curbuf->b_op_start.lnum + (y_type == MCHAR) - 1 + nr_lines
2214-
< curbuf->b_ml.ml_line_count
2215-
#ifdef FEAT_DIFF
2216-
|| curwin->w_p_diff
2217-
#endif
2218-
)
2219-
mark_adjust(curbuf->b_op_start.lnum + (y_type == MCHAR),
2211+
mark_adjust(curbuf->b_op_start.lnum + (y_type == MCHAR),
22202212
(linenr_T)MAXLNUM, nr_lines, 0L);
22212213

22222214
// note changed text for displaying and folding

src/testdir/test_fold.vim

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,4 +1683,17 @@ func Test_indent_with_L_command()
16831683
bwipe!
16841684
endfunc
16851685

1686+
" Make sure that when there is a fold at the bottom of the buffer and a newline
1687+
" character is appended to the line, the fold gets expanded (instead of the new
1688+
" line not being part of the fold).
1689+
func Test_expand_fold_at_bottom_of_buffer()
1690+
new
1691+
" create a fold on the only line
1692+
fold
1693+
execute "normal A\<CR>"
1694+
call assert_equal([1, 1], range(1, 2)->map('foldlevel(v:val)'))
1695+
1696+
bwipe!
1697+
endfunc
1698+
16861699
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,8 @@ static char *(features[]) =
695695

696696
static int included_patches[] =
697697
{ /* Add new patch number below this line */
698+
/**/
699+
1213,
698700
/**/
699701
1212,
700702
/**/

0 commit comments

Comments
 (0)