diff options
author | Brandon Simmons <simmsbra@gmail.com> | 2022-04-23 13:50:17 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-04-23 13:50:17 +0100 |
commit | 2c40707baa13a53cac4137ffb8b2ac67f50cea63 (patch) | |
tree | 260b40a241950eb8fbe5cad245dfe9f6c8beb768 | |
parent | 8279cfe49961b3711c84c66a9954c9f70e9b78c8 (diff) | |
download | vim-git-2c40707baa13a53cac4137ffb8b2ac67f50cea63.tar.gz |
patch 8.2.4813: pasting text while indent folding may mess up foldsv8.2.4813
Problem: Pasting text while indent folding may mess up folds.
Solution: Adjust the way folds are split. (Brandon Simmons, closes #10254)
-rw-r--r-- | src/fold.c | 5 | ||||
-rw-r--r-- | src/testdir/test_fold.vim | 20 | ||||
-rw-r--r-- | src/version.c | 2 |
3 files changed, 25 insertions, 2 deletions
diff --git a/src/fold.c b/src/fold.c index 8078e3af8..229cb2ad2 100644 --- a/src/fold.c +++ b/src/fold.c @@ -1128,7 +1128,7 @@ cloneFoldGrowArray(garray_T *from, garray_T *to) // foldFind() {{{2 /* * Search for line "lnum" in folds of growarray "gap". - * Set *fpp to the fold struct for the fold that contains "lnum" or + * Set "*fpp" to the fold struct for the fold that contains "lnum" or * the first fold below it (careful: it can be beyond the end of the array!). * Returns FALSE when there is no fold that contains "lnum". */ @@ -2911,7 +2911,8 @@ foldSplit( // any between top and bot, they have been removed by the caller. gap1 = &fp->fd_nested; gap2 = &fp[1].fd_nested; - if (foldFind(gap1, bot + 1 - fp->fd_top, &fp2)) + (void)foldFind(gap1, bot + 1 - fp->fd_top, &fp2); + if (fp2 != NULL) { len = (int)((fold_T *)gap1->ga_data + gap1->ga_len - fp2); if (len > 0 && ga_grow(gap2, len) == OK) diff --git a/src/testdir/test_fold.vim b/src/testdir/test_fold.vim index e3b6b6e58..3abb81aaf 100644 --- a/src/testdir/test_fold.vim +++ b/src/testdir/test_fold.vim @@ -1439,4 +1439,24 @@ func Test_foldtext_scriptlocal_func() delfunc s:FoldText endfunc +" Make sure a fold containing a nested fold is split correctly when using +" foldmethod=indent +func Test_fold_split() + new + let lines =<< trim END + line 1 + line 2 + line 3 + line 4 + line 5 + END + call setline(1, lines) + setlocal sw=2 + setlocal foldmethod=indent foldenable + call assert_equal([0, 1, 1, 2, 2], range(1, 5)->map('foldlevel(v:val)')) + call append(2, 'line 2.5') + call assert_equal([0, 1, 0, 1, 2, 2], range(1, 6)->map('foldlevel(v:val)')) + bw! +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/version.c b/src/version.c index 078f96818..7530c1b54 100644 --- a/src/version.c +++ b/src/version.c @@ -747,6 +747,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 4813, +/**/ 4812, /**/ 4811, |