Mercurial > vim
diff src/indent.c @ 28536:b6f2f545f8cc v8.2.4792
patch 8.2.4792: indent operator creates an undo entry for every line
Commit: https://github.com/vim/vim/commit/e4686989944bffdbcf59890aa21091b135528618
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Apr 19 18:28:45 2022 +0100
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 https://github.com/vim/vim/issues/10227)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 19 Apr 2022 19:30:03 +0200 |
parents | c3b34e4bbe34 |
children | 63e9b0016a6c |
line wrap: on
line diff
--- a/src/indent.c +++ b/src/indent.c @@ -1060,40 +1060,44 @@ op_reindent(oparg_T *oap, int (*how)(voi 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. - - 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. -# ifdef FEAT_LISP - if (i != oap->line_count - 1 || oap->line_count == 1 - || how != get_lisp_indent) -# endif + // 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; ) { - l = skipwhite(ml_get_curline()); - if (*l == NUL) // empty or blank line - amount = 0; - else - amount = how(); // get the indent for this line + // it's a slow thing to do, so give feedback so there's no worry + // that the computer's just hung. - if (amount >= 0 && set_indent(amount, SIN_UNDO)) + 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. +# ifdef FEAT_LISP + if (i != oap->line_count - 1 || oap->line_count == 1 + || how != get_lisp_indent) +# endif { - // 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;