aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ops.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-04-20 08:16:41 +0800
committerzeertzjq <zeertzjq@outlook.com>2022-04-21 07:24:50 +0800
commitf8b832b171d95aa3fb8e97a013d4a5717ff593c1 (patch)
treedc0ef2b3b6afff4e3365bfe554f244b63ebc5ace /src/nvim/ops.c
parentc72857d396f03fb570a3df4fa1abd074974f0c76 (diff)
downloadrneovim-f8b832b171d95aa3fb8e97a013d4a5717ff593c1.tar.gz
rneovim-f8b832b171d95aa3fb8e97a013d4a5717ff593c1.tar.bz2
rneovim-f8b832b171d95aa3fb8e97a013d4a5717ff593c1.zip
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) https://github.com/vim/vim/commit/e4686989944bffdbcf59890aa21091b135528618
Diffstat (limited to 'src/nvim/ops.c')
-rw-r--r--src/nvim/ops.c61
1 files changed, 32 insertions, 29 deletions
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
index badc00fb39..075497cd18 100644
--- a/src/nvim/ops.c
+++ b/src/nvim/ops.c
@@ -649,38 +649,41 @@ void op_reindent(oparg_T *oap, Indenter how)
return;
}
- 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
- * the computer's just hung. */
-
- if (i > 1
- && (i % 50 == 0 || i == oap->line_count - 1)
- && oap->line_count > p_report) {
- smsg(_("%" PRId64 " lines to indent... "), (int64_t)i);
- }
-
- /*
- * Be vi-compatible: For lisp indenting the first line is not
- * indented, unless there is only one line.
- */
- if (i != oap->line_count - 1 || oap->line_count == 1
- || how != get_lisp_indent) {
- l = skipwhite(get_cursor_line_ptr());
- 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;
+ // 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--) {
+ // 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(_("%" PRId64 " lines to indent... "), (int64_t)i);
+ }
+
+ // Be vi-compatible: For lisp indenting the first line is not
+ // indented, unless there is only one line.
+ if (i != oap->line_count - 1 || oap->line_count == 1
+ || how != get_lisp_indent) {
+ l = skipwhite(get_cursor_line_ptr());
+ 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;
}
- 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