diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-04-19 18:28:45 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-04-19 18:28:45 +0100 |
commit | e4686989944bffdbcf59890aa21091b135528618 (patch) | |
tree | 5e84326c7daa5c02f705ea93eb77af82b1a81f91 | |
parent | fef4485ef58d5937b170c6dc69431359469fc9cd (diff) | |
download | vim-git-e4686989944bffdbcf59890aa21091b135528618.tar.gz |
patch 8.2.4792: indent operator creates an undo entry for every linev8.2.4792
Problem: Indent operator creates an undo entry for every line.
Solution: Create one undo entry for all lines. (closes #10227)
-rw-r--r-- | src/indent.c | 58 | ||||
-rw-r--r-- | src/testdir/test_indent.vim | 23 | ||||
-rw-r--r-- | src/version.c | 2 |
3 files changed, 56 insertions, 27 deletions
diff --git a/src/indent.c b/src/indent.c index 95bda2072..be9dd4b5b 100644 --- a/src/indent.c +++ b/src/indent.c @@ -1060,40 +1060,44 @@ op_reindent(oparg_T *oap, int (*how)(void)) return; } - for (i = oap->line_count; --i >= 0 && !got_int; ) - { - // it's a slow thing to do, so give feedback so there's no worry that - // the computer's just hung. + // Save for undo. Do this once for all lines, much faster than doing this + // for each line separately, especially when undoing. + if (u_savecommon(start_lnum - 1, start_lnum + oap->line_count, + start_lnum + oap->line_count, FALSE) == OK) + for (i = oap->line_count; --i >= 0 && !got_int; ) + { + // it's a slow thing to do, so give feedback so there's no worry + // that the computer's just hung. - if (i > 1 - && (i % 50 == 0 || i == oap->line_count - 1) - && oap->line_count > p_report) - smsg(_("%ld lines to indent... "), i); + if (i > 1 + && (i % 50 == 0 || i == oap->line_count - 1) + && oap->line_count > p_report) + smsg(_("%ld lines to indent... "), i); - // Be vi-compatible: For lisp indenting the first line is not - // indented, unless there is only one line. + // Be vi-compatible: For lisp indenting the first line is not + // indented, unless there is only one line. # ifdef FEAT_LISP - if (i != oap->line_count - 1 || oap->line_count == 1 - || how != get_lisp_indent) + if (i != oap->line_count - 1 || oap->line_count == 1 + || how != get_lisp_indent) # endif - { - l = skipwhite(ml_get_curline()); - if (*l == NUL) // empty or blank line - amount = 0; - else - amount = how(); // get the indent for this line - - if (amount >= 0 && set_indent(amount, SIN_UNDO)) { - // did change the indent, call changed_lines() later - if (first_changed == 0) - first_changed = curwin->w_cursor.lnum; - last_changed = curwin->w_cursor.lnum; + l = skipwhite(ml_get_curline()); + if (*l == NUL) // empty or blank line + amount = 0; + else + amount = how(); // get the indent for this line + + if (amount >= 0 && set_indent(amount, 0)) + { + // did change the indent, call changed_lines() later + if (first_changed == 0) + first_changed = curwin->w_cursor.lnum; + last_changed = curwin->w_cursor.lnum; + } } + ++curwin->w_cursor.lnum; + curwin->w_cursor.col = 0; // make sure it's valid } - ++curwin->w_cursor.lnum; - curwin->w_cursor.col = 0; // make sure it's valid - } // put cursor on first non-blank of indented line curwin->w_cursor.lnum = start_lnum; diff --git a/src/testdir/test_indent.vim b/src/testdir/test_indent.vim index f96da6969..be55227bd 100644 --- a/src/testdir/test_indent.vim +++ b/src/testdir/test_indent.vim @@ -59,6 +59,29 @@ func Test_reindent() close! endfunc +" Test indent operator creating one undo entry +func Test_indent_operator_undo() + enew + call setline(1, range(12)->map('"\t" .. v:val')) + func FoldExpr() + let g:foldcount += 1 + return '=' + endfunc + set foldmethod=expr foldexpr=FoldExpr() + let g:foldcount = 0 + redraw + call assert_equal(12, g:foldcount) + normal gg=G + call assert_equal(24, g:foldcount) + undo + call assert_equal(38, g:foldcount) + + bwipe! + set foldmethod& foldexpr= + delfunc FoldExpr + unlet g:foldcount +endfunc + " Test for shifting a line with a preprocessor directive ('#') func Test_preproc_indent() new diff --git a/src/version.c b/src/version.c index b00e0e832..82d10a285 100644 --- a/src/version.c +++ b/src/version.c @@ -747,6 +747,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 4792, +/**/ 4791, /**/ 4790, |