vim-patch:8.2.4813: pasting text while indent folding may mess up folds

Problem:    Pasting text while indent folding may mess up folds.
Solution:   Adjust the way folds are split. (Brandon Simmons, closes vim/vim#10254)
2c40707baa
This commit is contained in:
zeertzjq 2022-04-24 21:48:07 +08:00
parent 3e41e7d9c1
commit 2511f3e76d
2 changed files with 23 additions and 2 deletions

View File

@ -1058,7 +1058,7 @@ void 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!).
///
/// @return false when there is no fold that contains "lnum".
@ -2615,7 +2615,8 @@ static void foldSplit(buf_T *buf, garray_T *const gap, const int i, const linenr
// any between top and bot, they have been removed by the caller.
garray_T *const gap1 = &fp->fd_nested;
garray_T *const 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) {
const int len = (int)((fold_T *)gap1->ga_data + gap1->ga_len - fp2);
if (len > 0) {
ga_grow(gap2, len);

View File

@ -881,4 +881,24 @@ func Test_fold_relative_move()
set fdm& sw& wrap& tw&
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