comparison src/ex_docmd.c @ 31053:39f96b1e7b8d v9.0.0861

patch 9.0.0861: solution for "!!sort" in closed fold is not optimal Commit: https://github.com/vim/vim/commit/9954dc39ea090cee6bf41c888c41e60d9f52c3b8 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Nov 11 22:58:36 2022 +0000 patch 9.0.0861: solution for "!!sort" in closed fold is not optimal 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)
author Bram Moolenaar <Bram@vim.org>
date Sat, 12 Nov 2022 00:00:04 +0100
parents bee731901f4f
children f6d4c6a3b41c
comparison
equal deleted inserted replaced
31052:2187b5ee2e89 31053:39f96b1e7b8d
4306 4306
4307 cmd = skipwhite(*ptr); 4307 cmd = skipwhite(*ptr);
4308 lnum = MAXLNUM; 4308 lnum = MAXLNUM;
4309 do 4309 do
4310 { 4310 {
4311 #ifdef FEAT_FOLDING
4312 int base_char = *cmd;
4313 #endif
4314 switch (*cmd) 4311 switch (*cmd)
4315 { 4312 {
4316 case '.': // '.' - Cursor position 4313 case '.': // '.' - Cursor position
4317 ++cmd; 4314 ++cmd;
4318 switch (addr_type) 4315 switch (addr_type)
4629 lnum = compute_buffer_local_count( 4626 lnum = compute_buffer_local_count(
4630 addr_type, lnum, (i == '-') ? -1 * n : n); 4627 addr_type, lnum, (i == '-') ? -1 * n : n);
4631 else 4628 else
4632 { 4629 {
4633 #ifdef FEAT_FOLDING 4630 #ifdef FEAT_FOLDING
4634 // Relative line addressing: need to adjust for closed folds 4631 // Relative line addressing: need to adjust for lines in a
4635 // after the first address. 4632 // closed fold after the first address.
4636 // Subtle difference: "number,+number" and "number,-number" 4633 if (addr_type == ADDR_LINES && (i == '-' || i == '+')
4637 // adjusts to end of closed fold before adding/subtracting, 4634 && address_count >= 2)
4638 // while "number,.+number" adjusts to end of closed fold after
4639 // adding to make "!!" expanded into ".,.+N" work correctly.
4640 int adjust_for_folding = addr_type == ADDR_LINES
4641 && (i == '-' || i == '+')
4642 && address_count >= 2;
4643 if (adjust_for_folding && (i == '-' || base_char != '.'))
4644 (void)hasFolding(lnum, NULL, &lnum); 4635 (void)hasFolding(lnum, NULL, &lnum);
4645 #endif 4636 #endif
4646 if (i == '-') 4637 if (i == '-')
4647 lnum -= n; 4638 lnum -= n;
4648 else 4639 else
4651 { 4642 {
4652 emsg(_(e_line_number_out_of_range)); 4643 emsg(_(e_line_number_out_of_range));
4653 goto error; 4644 goto error;
4654 } 4645 }
4655 lnum += n; 4646 lnum += n;
4656 #ifdef FEAT_FOLDING
4657 // ".+number" rounds up to the end of a closed fold after
4658 // adding, so that ":!!sort" sorts one closed fold.
4659 if (adjust_for_folding && base_char == '.')
4660 (void)hasFolding(lnum, NULL, &lnum);
4661 #endif
4662 } 4647 }
4663 } 4648 }
4664 } 4649 }
4665 } while (*cmd == '/' || *cmd == '?'); 4650 } while (*cmd == '/' || *cmd == '?');
4666 4651