changeset 20187:79cc97206476 v8.2.0649

patch 8.2.0649: undo problem whn an InsertLeave autocommand resets undo Commit: https://github.com/vim/vim/commit/db93495d276642f63f80471fbcb900b9aa1e9e42 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Apr 27 20:18:31 2020 +0200 patch 8.2.0649: undo problem whn an InsertLeave autocommand resets undo Problem: Undo problem whn an InsertLeave autocommand resets undo. (Kutsan Kaplan) Solution: Do not create a new undo block when leaving Insert mode.
author Bram Moolenaar <Bram@vim.org>
date Mon, 27 Apr 2020 20:30:03 +0200
parents 7ea93344ec03
children 085eb4da46f4
files src/edit.c src/testdir/test_edit.vim src/version.c
diffstat 3 files changed, 20 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/edit.c
+++ b/src/edit.c
@@ -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;
--- a/src/testdir/test_edit.vim
+++ b/src/testdir/test_edit.vim
@@ -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
--- 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 */
 /**/
+    649,
+/**/
     648,
 /**/
     647,