]> granicus.if.org Git - vim/commitdiff
patch 8.2.0649: undo problem whn an InsertLeave autocommand resets undo v8.2.0649
authorBram Moolenaar <Bram@vim.org>
Mon, 27 Apr 2020 18:18:31 +0000 (20:18 +0200)
committerBram Moolenaar <Bram@vim.org>
Mon, 27 Apr 2020 18:18:31 +0000 (20:18 +0200)
Problem:    Undo problem whn an InsertLeave autocommand resets undo. (Kutsan
            Kaplan)
Solution:   Do not create a new undo block when leaving Insert mode.

src/edit.c
src/testdir/test_edit.vim
src/version.c

index 05518ceab8490ec3d581200205557c7452523873..7f4f765012d8b304c43437573546270097d98839 100644 (file)
@@ -5994,7 +5994,8 @@ ins_apply_autocmds(event_T event)
 
     // If u_savesub() was called then we are not prepared to start
     // a new line.  Call u_save() with no contents to fix that.
-    if (tick != CHANGEDTICK(curbuf))
+    // Except when leaving Insert mode.
+    if (event != EVENT_INSERTLEAVE && tick != CHANGEDTICK(curbuf))
        u_save(curwin->w_cursor.lnum, (linenr_T)(curwin->w_cursor.lnum + 1));
 
     return r;
index ce55f6be0b53f048c811ceb2c783b0904138bf28..a9ba31df4c1f7b18a878571aa1cdfe4343a9f1d2 100644 (file)
@@ -1444,7 +1444,7 @@ func Test_edit_alt()
   call delete('XAltFile')
 endfunc
 
-func Test_leave_insert_autocmd()
+func Test_edit_InsertLeave()
   new
   au InsertLeave * let g:did_au = 1
   let g:did_au = 0
@@ -1474,6 +1474,21 @@ func Test_leave_insert_autocmd()
   iunmap x
 endfunc
 
+func Test_edit_InsertLeave_undo()
+  new XtestUndo
+  set undofile
+  au InsertLeave * wall
+  exe "normal ofoo\<Esc>"
+  call assert_equal(2, line('$'))
+  normal u
+  call assert_equal(1, line('$'))
+
+  bwipe!
+  au! InsertLeave
+  call delete('XtestUndo')
+  set undofile&
+endfunc
+
 " Test for inserting characters using CTRL-V followed by a number.
 func Test_edit_special_chars()
   new
index a9a2e293e8bb4d1d4f13665c9c7fb8f3e433cdde..fa91a2bc04b7fc104195c788174c65fba0a9d285 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    649,
 /**/
     648,
 /**/