aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ops.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-11-12 07:43:36 +0800
committerGitHub <noreply@github.com>2022-11-12 07:43:36 +0800
commiteee956051637a5dff02ba6c6083fbffc87c0c96e (patch)
treebd08a4983f10ffe914ce0c668e1d7b4a5ed4337d /src/nvim/ops.c
parent0d7cc5ee85c2722ab68e276a2bfda336ef9429d5 (diff)
downloadrneovim-eee956051637a5dff02ba6c6083fbffc87c0c96e.tar.gz
rneovim-eee956051637a5dff02ba6c6083fbffc87c0c96e.tar.bz2
rneovim-eee956051637a5dff02ba6c6083fbffc87c0c96e.zip
vim-patch:9.0.0861: solution for "!!sort" in closed fold is not optimal (#21027)
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 vim/vim#11487) https://github.com/vim/vim/commit/9954dc39ea090cee6bf41c888c41e60d9f52c3b8 Co-authored-by: Bram Moolenaar <Bram@vim.org>
Diffstat (limited to 'src/nvim/ops.c')
-rw-r--r--src/nvim/ops.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
index 65fc42bc08..8656b4265d 100644
--- a/src/nvim/ops.c
+++ b/src/nvim/ops.c
@@ -5555,13 +5555,22 @@ static void op_colon(oparg_T *oap)
} else {
stuffnumReadbuff((long)oap->start.lnum);
}
- if (oap->end.lnum != oap->start.lnum) {
+
+ // 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);
+ if (oap->end.lnum != oap->start.lnum && oap->end.lnum != endOfStartFold) {
+ // 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
+ // do not use ".+number" for a closed fold, it would count
+ // folded lines twice
+ && !hasFolding(oap->end.lnum, NULL, NULL)) {
stuffReadbuff(".+");
stuffnumReadbuff(oap->line_count - 1);
} else {