0
0
mirror of https://github.com/vim/vim.git synced 2025-09-29 04:34:16 -04:00

patch 8.2.4792: indent operator creates an undo entry for every line

Problem:    Indent operator creates an undo entry for every line.
Solution:   Create one undo entry for all lines. (closes #10227)
This commit is contained in:
Bram Moolenaar
2022-04-19 18:28:45 +01:00
parent fef4485ef5
commit e468698994
3 changed files with 58 additions and 29 deletions

View File

@@ -1060,10 +1060,14 @@ op_reindent(oparg_T *oap, int (*how)(void))
return;
}
// 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.
// 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)
@@ -1083,7 +1087,7 @@ op_reindent(oparg_T *oap, int (*how)(void))
else
amount = how(); // get the indent for this line
if (amount >= 0 && set_indent(amount, SIN_UNDO))
if (amount >= 0 && set_indent(amount, 0))
{
// did change the indent, call changed_lines() later
if (first_changed == 0)

View File

@@ -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

View File

@@ -746,6 +746,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
4792,
/**/
4791,
/**/