mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 11:28:22 +00:00
vim-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 vim/vim#10227)
e468698994
This commit is contained in:
@@ -649,9 +649,13 @@ void op_reindent(oparg_T *oap, Indenter how)
|
|||||||
return;
|
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(curbuf, start_lnum - 1, start_lnum + oap->line_count,
|
||||||
|
start_lnum + oap->line_count, false) == OK) {
|
||||||
for (i = oap->line_count - 1; i >= 0 && !got_int; i--) {
|
for (i = oap->line_count - 1; i >= 0 && !got_int; i--) {
|
||||||
/* it's a slow thing to do, so give feedback so there's no worry that
|
// it's a slow thing to do, so give feedback so there's no worry
|
||||||
* the computer's just hung. */
|
// that the computer's just hung.
|
||||||
|
|
||||||
if (i > 1
|
if (i > 1
|
||||||
&& (i % 50 == 0 || i == oap->line_count - 1)
|
&& (i % 50 == 0 || i == oap->line_count - 1)
|
||||||
@@ -659,10 +663,8 @@ void op_reindent(oparg_T *oap, Indenter how)
|
|||||||
smsg(_("%" PRId64 " lines to indent... "), (int64_t)i);
|
smsg(_("%" PRId64 " lines to indent... "), (int64_t)i);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// Be vi-compatible: For lisp indenting the first line is not
|
||||||
* Be vi-compatible: For lisp indenting the first line is not
|
// indented, unless there is only one line.
|
||||||
* indented, unless there is only one line.
|
|
||||||
*/
|
|
||||||
if (i != oap->line_count - 1 || oap->line_count == 1
|
if (i != oap->line_count - 1 || oap->line_count == 1
|
||||||
|| how != get_lisp_indent) {
|
|| how != get_lisp_indent) {
|
||||||
l = skipwhite(get_cursor_line_ptr());
|
l = skipwhite(get_cursor_line_ptr());
|
||||||
@@ -671,7 +673,7 @@ void op_reindent(oparg_T *oap, Indenter how)
|
|||||||
} else {
|
} else {
|
||||||
amount = how(); // get the indent for this line
|
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
|
// did change the indent, call changed_lines() later
|
||||||
if (first_changed == 0) {
|
if (first_changed == 0) {
|
||||||
first_changed = curwin->w_cursor.lnum;
|
first_changed = curwin->w_cursor.lnum;
|
||||||
@@ -679,9 +681,10 @@ void op_reindent(oparg_T *oap, Indenter how)
|
|||||||
last_changed = curwin->w_cursor.lnum;
|
last_changed = curwin->w_cursor.lnum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
++curwin->w_cursor.lnum;
|
curwin->w_cursor.lnum++;
|
||||||
curwin->w_cursor.col = 0; // make sure it's valid
|
curwin->w_cursor.col = 0; // make sure it's valid
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// put cursor on first non-blank of indented line
|
// put cursor on first non-blank of indented line
|
||||||
curwin->w_cursor.lnum = start_lnum;
|
curwin->w_cursor.lnum = start_lnum;
|
||||||
|
@@ -59,6 +59,29 @@ func Test_reindent()
|
|||||||
close!
|
close!
|
||||||
endfunc
|
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 ('#')
|
" Test for shifting a line with a preprocessor directive ('#')
|
||||||
func Test_preproc_indent()
|
func Test_preproc_indent()
|
||||||
new
|
new
|
||||||
|
Reference in New Issue
Block a user