summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLemonBoy <thatlemon@gmail.com>2022-05-12 15:39:31 +0100
committerBram Moolenaar <Bram@vim.org>2022-05-12 15:39:31 +0100
commit82444cefa3fef87624a078ea86a72af7ef4ef42e (patch)
tree7ec703a5fd5b1d641a731868e9bab06ef4d32f92
parentd0132f4862342eebe6d8e7a9096adf956ba6588b (diff)
patch 8.2.4941: '[ and '] marks may be wrong after undov8.2.4941
Problem: '[ and '] marks may be wrong after undo. Solution: Adjust the '[ and '] marks if needed. (closes #10407, closes #1281)
-rw-r--r--src/testdir/test_undo.vim17
-rw-r--r--src/undo.c9
-rw-r--r--src/version.c2
3 files changed, 27 insertions, 1 deletions
diff --git a/src/testdir/test_undo.vim b/src/testdir/test_undo.vim
index bfcc538d93..596944cdf3 100644
--- a/src/testdir/test_undo.vim
+++ b/src/testdir/test_undo.vim
@@ -756,4 +756,21 @@ func Test_redo_multibyte_in_insert_mode()
bwipe!
endfunc
+func Test_undo_mark()
+ new
+ " The undo is applied to the only line.
+ call setline(1, 'hello')
+ call feedkeys("ggyiw$p", 'xt')
+ undo
+ call assert_equal([0, 1, 1, 0], getpos("'["))
+ call assert_equal([0, 1, 1, 0], getpos("']"))
+ " The undo removes the last line.
+ call feedkeys("Goaaaa\<Esc>", 'xt')
+ call feedkeys("obbbb\<Esc>", 'xt')
+ undo
+ call assert_equal([0, 2, 1, 0], getpos("'["))
+ call assert_equal([0, 2, 1, 0], getpos("']"))
+ bwipe!
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/undo.c b/src/undo.c
index 56efb44816..cac09f0f58 100644
--- a/src/undo.c
+++ b/src/undo.c
@@ -2831,9 +2831,10 @@ u_undoredo(int undo)
if (oldsize > 0 || newsize > 0)
changed_lines(top + 1, 0, bot, newsize - oldsize);
- // set '[ and '] mark
+ // Set the '[ mark.
if (top + 1 < curbuf->b_op_start.lnum)
curbuf->b_op_start.lnum = top + 1;
+ // Set the '] mark.
if (newsize == 0 && top + 1 > curbuf->b_op_end.lnum)
curbuf->b_op_end.lnum = top + 1;
else if (top + newsize > curbuf->b_op_end.lnum)
@@ -2853,6 +2854,12 @@ u_undoredo(int undo)
newlist = uep;
}
+ // Ensure the '[ and '] marks are within bounds.
+ if (curbuf->b_op_start.lnum > curbuf->b_ml.ml_line_count)
+ curbuf->b_op_start.lnum = curbuf->b_ml.ml_line_count;
+ if (curbuf->b_op_end.lnum > curbuf->b_ml.ml_line_count)
+ curbuf->b_op_end.lnum = curbuf->b_ml.ml_line_count;
+
// Set the cursor to the desired position. Check that the line is valid.
curwin->w_cursor = new_curpos;
check_cursor_lnum();
diff --git a/src/version.c b/src/version.c
index 9c33c3f361..f34a3226e9 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 */
/**/
+ 4941,
+/**/
4940,
/**/
4939,