Patch 8.2.4941
Problem:    '[ and '] marks may be wrong after undo.
Solution:   Adjust the '[ and '] marks if needed. (closes #10407, closes #1281)
Files:      src/undo.c, src/testdir/test_undo.vim


*** ../vim-8.2.4940/src/undo.c  2022-04-15 13:53:30.056708670 +0100
--- src/undo.c  2022-05-12 15:34:04.843826635 +0100
***************
*** 2831,2839 ****
        if (oldsize > 0 || newsize > 0)
            changed_lines(top + 1, 0, bot, newsize - oldsize);
  
!       // set '[ and '] mark
        if (top + 1 < curbuf->b_op_start.lnum)
            curbuf->b_op_start.lnum = top + 1;
        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)
--- 2831,2840 ----
        if (oldsize > 0 || newsize > 0)
            changed_lines(top + 1, 0, bot, newsize - oldsize);
  
!       // 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,2858 ****
--- 2854,2865 ----
        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();
*** ../vim-8.2.4940/src/testdir/test_undo.vim   2021-08-21 16:13:08.569405922 
+0100
--- src/testdir/test_undo.vim   2022-05-12 15:34:04.839826637 +0100
***************
*** 756,759 ****
--- 756,776 ----
    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
*** ../vim-8.2.4940/src/version.c       2022-05-12 11:05:36.184621676 +0100
--- src/version.c       2022-05-12 15:35:41.991794150 +0100
***************
*** 748,749 ****
--- 748,751 ----
  {   /* Add new patch number below this line */
+ /**/
+     4941,
  /**/

-- 
If Microsoft would build a car...
... You'd have to press the "Start" button to turn the engine off.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20220512144007.192691C1EE1%40moolenaar.net.

Raspunde prin e-mail lui