diff options
author | Bram Moolenaar <Bram@vim.org> | 2019-08-19 22:48:30 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2019-08-19 22:48:30 +0200 |
commit | 9a4a8c4d5993c6371486c895a515c2ad351e9aaa (patch) | |
tree | 8edb7b29042b5c89c345c5df3220f715eeecf39b | |
parent | ea7ecfe2a08877f98edec9b9c26b9e1b3673f00b (diff) | |
download | vim-git-9a4a8c4d5993c6371486c895a515c2ad351e9aaa.tar.gz |
patch 8.1.1890: ml_get error when deleting fold markerv8.1.1890
Problem: Ml_get error when deleting fold marker.
Solution: Check that the line number is not below the last line. Adjust the
fold when deleting the empty line. (Christian Brabandt,
closes #4834)
-rw-r--r-- | src/fold.c | 14 | ||||
-rw-r--r-- | src/normal.c | 5 | ||||
-rw-r--r-- | src/testdir/test_fold.vim | 16 | ||||
-rw-r--r-- | src/version.c | 2 |
4 files changed, 32 insertions, 5 deletions
diff --git a/src/fold.c b/src/fold.c index 4cc7a477d..482d3c968 100644 --- a/src/fold.c +++ b/src/fold.c @@ -1813,7 +1813,7 @@ deleteFoldMarkers( /* * Delete marker "marker[markerlen]" at the end of line "lnum". * Delete 'commentstring' if it matches. - * If the marker is not found, there is no error message. Could a missing + * If the marker is not found, there is no error message. Could be a missing * close-marker. */ static void @@ -1826,6 +1826,9 @@ foldDelMarker(linenr_T lnum, char_u *marker, int markerlen) char_u *cms = curbuf->b_p_cms; char_u *cms2; + // end marker may be missing and fold extends below the last line + if (lnum > curbuf->b_ml.ml_line_count) + return; line = ml_get(lnum); for (p = line; *p != NUL; ++p) if (STRNCMP(p, marker, markerlen) == 0) @@ -2733,16 +2736,19 @@ foldUpdateIEMSRecurse( * lvl >= level: fold continues below "bot" */ - /* Current fold at least extends until lnum. */ + // Current fold at least extends until lnum. if (fp->fd_len < flp->lnum - fp->fd_top) { fp->fd_len = flp->lnum - fp->fd_top; fp->fd_small = MAYBE; fold_changed = TRUE; } + else if (fp->fd_top + fp->fd_len > linecount) + // running into the end of the buffer (deleted last line) + fp->fd_len = linecount - fp->fd_top + 1; - /* Delete contained folds from the end of the last one found until where - * we stopped looking. */ + // Delete contained folds from the end of the last one found until where + // we stopped looking. foldRemove(&fp->fd_nested, startlnum2 - fp->fd_top, flp->lnum - 1 - fp->fd_top); diff --git a/src/normal.c b/src/normal.c index 7951bd5c3..1db1d16ab 100644 --- a/src/normal.c +++ b/src/normal.c @@ -9346,13 +9346,15 @@ nv_put_opt(cmdarg_T *cap, int fix_indent) reg1 = get_register(regname, TRUE); } - /* Now delete the selected text. */ + // Now delete the selected text. Avoid messages here. cap->cmdchar = 'd'; cap->nchar = NUL; cap->oap->regname = NUL; + ++msg_silent; nv_operator(cap); do_pending_operator(cap, 0, FALSE); empty = (curbuf->b_ml.ml_flags & ML_EMPTY); + --msg_silent; /* delete PUT_LINE_BACKWARD; */ cap->oap->regname = regname; @@ -9407,6 +9409,7 @@ nv_put_opt(cmdarg_T *cap, int fix_indent) if (empty && *ml_get(curbuf->b_ml.ml_line_count) == NUL) { ml_delete(curbuf->b_ml.ml_line_count, TRUE); + deleted_lines(curbuf->b_ml.ml_line_count + 1, 1); /* If the cursor was in that line, move it to the end of the last * line. */ diff --git a/src/testdir/test_fold.vim b/src/testdir/test_fold.vim index dc5879516..1d5259f6b 100644 --- a/src/testdir/test_fold.vim +++ b/src/testdir/test_fold.vim @@ -741,3 +741,19 @@ func Test_folds_marker_in_comment2() set foldmethod& bwipe! endfunc + +func Test_fold_delete_with_marker() + new + call setline(1, ['func Func() {{{1', 'endfunc']) + 1,2yank + new + set fdm=marker + call setline(1, 'x') + normal! Vp + normal! zd + call assert_equal(['func Func() ', 'endfunc'], getline(1, '$')) + + set fdm& + bwipe! + bwipe! +endfunc diff --git a/src/version.c b/src/version.c index d7bdfa2c0..c6944cf4f 100644 --- a/src/version.c +++ b/src/version.c @@ -766,6 +766,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1890, +/**/ 1889, /**/ 1888, |