To: vim_dev@googlegroups.com Subject: Patch 8.2.4813 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.4813 Problem: Pasting text while indent folding may mess up folds. Solution: Adjust the way folds are split. (Brandon Simmons, closes #10254) Files: src/fold.c, src/testdir/test_fold.vim *** ../vim-8.2.4812/src/fold.c 2022-02-16 19:24:03.622162411 +0000 --- src/fold.c 2022-04-23 13:47:57.987510144 +0100 *************** *** 1128,1134 **** // foldFind() {{{2 /* * Search for line "lnum" in folds of growarray "gap". ! * 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". */ --- 1128,1134 ---- // foldFind() {{{2 /* * Search for line "lnum" in folds of growarray "gap". ! * 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,2917 **** // 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)) { len = (int)((fold_T *)gap1->ga_data + gap1->ga_len - fp2); if (len > 0 && ga_grow(gap2, len) == OK) --- 2911,2918 ---- // any between top and bot, they have been removed by the caller. gap1 = &fp->fd_nested; gap2 = &fp[1].fd_nested; ! (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) *** ../vim-8.2.4812/src/testdir/test_fold.vim 2021-12-26 21:54:38.128433097 +0000 --- src/testdir/test_fold.vim 2022-04-23 13:44:02.919605017 +0100 *************** *** 1439,1442 **** --- 1439,1462 ---- 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 *** ../vim-8.2.4812/src/version.c 2022-04-23 12:05:47.398319460 +0100 --- src/version.c 2022-04-23 13:46:34.347544253 +0100 *************** *** 748,749 **** --- 748,751 ---- { /* Add new patch number below this line */ + /**/ + 4813, /**/ -- Despite the cost of living, have you noticed how it remains so popular? /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///