patch 9.2.0384: stale Insstart after <Cmd> cursor move breaks undo

Commit: 
https://github.com/vim/vim/commit/d4fb31762ea0b9de6fffb529c4ffee509621f74c
Author: Jaehwang Jung <[email protected]>
Date:   Tue Apr 21 19:21:24 2026 +0000

    patch 9.2.0384: stale Insstart after <Cmd> cursor move breaks undo
    
    Problem:  A <Cmd> command executed from Insert mode can sync undo and
              move the cursor before the next edit. stop_arrow() saved the
              new cursor line for undo, but left Insstart at the previous
              insertion point. A line-start backspace could then delete
              lines above the saved line without saving the joined range,
              leaving a pending undo entry whose bottom resolved above
              its top and raising E340.
    Solution: Update Insstart and Insstart_textlen after the pending undo
              save so the next edit starts from the command-updated cursor
              position (Jaehwang Jung).
    
    closes: #20031
    
    AI-assisted: Codex
    
    Signed-off-by: Jaehwang Jung <[email protected]>
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/src/edit.c b/src/edit.c
index 60cae0e15..f15cc55f3 100644
--- a/src/edit.c
+++ b/src/edit.c
@@ -2502,7 +2502,12 @@ stop_arrow(void)
     else if (ins_need_undo)
     {
        if (u_save_cursor() == OK)
+       {
+           // A command or event may have moved the cursor after syncing undo.
+           Insstart = curwin->w_cursor;
+           Insstart_textlen = (colnr_T)linetabsize_str(ml_get_curline());
            ins_need_undo = FALSE;
+       }
     }
 
 #ifdef FEAT_FOLDING
diff --git a/src/testdir/test_undo.vim b/src/testdir/test_undo.vim
index ad724aa04..97b77f423 100644
--- a/src/testdir/test_undo.vim
+++ b/src/testdir/test_undo.vim
@@ -924,5 +924,19 @@ func Test_restore_cursor_position_after_undo()
   bw!
 endfunc
 
+func Test_undo_line_backspace_after_insert_cmd_cursor_movement()
+  new
+  setlocal backspace=eol undolevels=100
+  call setline(1, ['', '', 'abc', 'def'])
+  call cursor(4, 1)
+
+  let v:errmsg = ''
+  call feedkeys("i\<Cmd>setlocal undolevels=101 | call cursor(3, 1)\<CR>"
+        \ .. "\<BS>\<BS>\<Esc>u", 'xt')
+
+  call assert_equal('', v:errmsg)
+  call assert_equal(['', '', 'abc', 'def'], getline(1, '$'))
+  bwipe!
+endfunc
 
 " vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index 895c22e9c..2a8b84404 100644
--- a/src/version.c
+++ b/src/version.c
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    384,
 /**/
     383,
 /**/

-- 
-- 
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 visit 
https://groups.google.com/d/msgid/vim_dev/E1wFGnM-00EFV0-3c%40256bit.org.

Raspunde prin e-mail lui