diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-11-11 22:58:36 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-11-11 22:58:36 +0000 |
commit | 9954dc39ea090cee6bf41c888c41e60d9f52c3b8 (patch) | |
tree | b9d60fd9a444278a01e4532467ea6606d680caf0 /src | |
parent | a20be06f97d45efabaa52ef107eb7959c0c623a2 (diff) |
patch 9.0.0861: solution for "!!sort" in closed fold is not optimalv9.0.0861
Problem: Solution for "!!sort" in closed fold is not optimal.
Solution: Use a different range instead of the subtle difference in handling
a range with an offset. (issue #11487)
Diffstat (limited to 'src')
-rw-r--r-- | src/ex_docmd.c | 23 | ||||
-rw-r--r-- | src/ops.c | 22 | ||||
-rw-r--r-- | src/testdir/test_fold.vim | 48 | ||||
-rw-r--r-- | src/version.c | 2 |
4 files changed, 74 insertions, 21 deletions
diff --git a/src/ex_docmd.c b/src/ex_docmd.c index 02bca38e04..d5037a4561 100644 --- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -4308,9 +4308,6 @@ get_address( lnum = MAXLNUM; do { -#ifdef FEAT_FOLDING - int base_char = *cmd; -#endif switch (*cmd) { case '.': // '.' - Cursor position @@ -4631,16 +4628,10 @@ get_address( else { #ifdef FEAT_FOLDING - // Relative line addressing: need to adjust for closed folds - // after the first address. - // Subtle difference: "number,+number" and "number,-number" - // adjusts to end of closed fold before adding/subtracting, - // while "number,.+number" adjusts to end of closed fold after - // adding to make "!!" expanded into ".,.+N" work correctly. - int adjust_for_folding = addr_type == ADDR_LINES - && (i == '-' || i == '+') - && address_count >= 2; - if (adjust_for_folding && (i == '-' || base_char != '.')) + // Relative line addressing: need to adjust for lines in a + // closed fold after the first address. + if (addr_type == ADDR_LINES && (i == '-' || i == '+') + && address_count >= 2) (void)hasFolding(lnum, NULL, &lnum); #endif if (i == '-') @@ -4653,12 +4644,6 @@ get_address( goto error; } lnum += n; -#ifdef FEAT_FOLDING - // ".+number" rounds up to the end of a closed fold after - // adding, so that ":!!sort" sorts one closed fold. - if (adjust_for_folding && base_char == '.') - (void)hasFolding(lnum, NULL, &lnum); -#endif } } } @@ -3333,14 +3333,32 @@ op_colon(oparg_T *oap) stuffcharReadbuff('.'); else stuffnumReadbuff((long)oap->start.lnum); - if (oap->end.lnum != oap->start.lnum) + +#ifdef FEAT_FOLDING + // When using !! on a closed fold the range ".!" works best to operate + // on, it will be made the whole closed fold later. + linenr_T endOfStartFold = oap->start.lnum; + (void)hasFolding(oap->start.lnum, NULL, &endOfStartFold); +#endif + if (oap->end.lnum != oap->start.lnum +#ifdef FEAT_FOLDING + && oap->end.lnum != endOfStartFold +#endif + ) { + // Make it a range with the end line. stuffcharReadbuff(','); if (oap->end.lnum == curwin->w_cursor.lnum) stuffcharReadbuff('.'); else if (oap->end.lnum == curbuf->b_ml.ml_line_count) stuffcharReadbuff('$'); - else if (oap->start.lnum == curwin->w_cursor.lnum) + else if (oap->start.lnum == curwin->w_cursor.lnum +#ifdef FEAT_FOLDING + // do not use ".+number" for a closed fold, it would count + // folded lines twice + && !hasFolding(oap->end.lnum, NULL, NULL) +#endif + ) { stuffReadbuff((char_u *)".+"); stuffnumReadbuff((long)oap->line_count - 1); diff --git a/src/testdir/test_fold.vim b/src/testdir/test_fold.vim index a14772134c..2f4aade013 100644 --- a/src/testdir/test_fold.vim +++ b/src/testdir/test_fold.vim @@ -72,6 +72,54 @@ func Test_address_fold() quit! endfunc +func Test_address_offsets() + " check the help for :range-closed-fold + enew + call setline(1, [ + \ '1 one', + \ '2 two', + \ '3 three', + \ '4 four FOLDED', + \ '5 five FOLDED', + \ '6 six', + \ '7 seven', + \ '8 eight', + \]) + set foldmethod=manual + normal 4Gvjzf + 3,4+2yank + call assert_equal([ + \ '3 three', + \ '4 four FOLDED', + \ '5 five FOLDED', + \ '6 six', + \ '7 seven', + \ ], getreg(0,1,1)) + + enew! + call setline(1, [ + \ '1 one', + \ '2 two', + \ '3 three FOLDED', + \ '4 four FOLDED', + \ '5 five FOLDED', + \ '6 six FOLDED', + \ '7 seven', + \ '8 eight', + \]) + normal 3Gv3jzf + 2,4-1yank + call assert_equal([ + \ '2 two', + \ '3 three FOLDED', + \ '4 four FOLDED', + \ '5 five FOLDED', + \ '6 six FOLDED', + \ ], getreg(0,1,1)) + + bwipe! +endfunc + func Test_indent_fold() new call setline(1, ['', 'a', ' b', ' c']) diff --git a/src/version.c b/src/version.c index 0e991a3ff8..dd6927301c 100644 --- a/src/version.c +++ b/src/version.c @@ -696,6 +696,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 861, +/**/ 860, /**/ 859, |