Patch 9.0.1036
Problem:    Undo misbehaves when writing from an insert mode mapping.
Solution:   Sync undo when writing. (closes #11674)
Files:      src/edit.c, src/testdir/test_undo.vim,
            src/testdir/dumps/Test_undo_after_write_1.dump,
            src/testdir/dumps/Test_undo_after_write_2.dump,
            src/testdir/dumps/Test_undo_after_write_2.vim


*** ../vim-9.0.1035/src/edit.c  2022-12-01 12:03:42.263227523 +0000
--- src/edit.c  2022-12-08 21:40:15.201035616 +0000
***************
*** 1049,1060 ****
  
        case K_COMMAND:             // <Cmd>command<CR>
        case K_SCRIPT_COMMAND:      // <ScriptCmd>command<CR>
!           do_cmdkey_command(c, 0);
  #ifdef FEAT_TERMINAL
!           if (term_use_loop())
!               // Started a terminal that gets the input, exit Insert mode.
!               goto doESCkey;
  #endif
            break;
  
        case K_CURSORHOLD:      // Didn't type something for a while.
--- 1049,1067 ----
  
        case K_COMMAND:             // <Cmd>command<CR>
        case K_SCRIPT_COMMAND:      // <ScriptCmd>command<CR>
!           {
!               do_cmdkey_command(c, 0);
! 
  #ifdef FEAT_TERMINAL
!               if (term_use_loop())
!                   // Started a terminal that gets the input, exit Insert mode.
!                   goto doESCkey;
  #endif
+               if (curbuf->b_u_synced)
+                   // The command caused undo to be synced.  Need to save the
+                   // line for undo before inserting the next char.
+                   ins_need_undo = TRUE;
+           }
            break;
  
        case K_CURSORHOLD:      // Didn't type something for a while.
*** ../vim-9.0.1035/src/testdir/test_undo.vim   2022-10-15 21:35:51.191403811 
+0100
--- src/testdir/test_undo.vim   2022-12-08 21:38:01.649013470 +0000
***************
*** 3,8 ****
--- 3,11 ----
  " undo-able pieces.  Do that by setting 'undolevels'.
  " Also tests :earlier and :later.
  
+ source check.vim
+ source screendump.vim
+ 
  func Test_undotree()
    new
  
***************
*** 775,778 ****
--- 778,807 ----
    bwipe!
  endfunc
  
+ func Test_undo_after_write()
+   " use a terminal to make undo work like when text is typed
+   CheckRunVimInTerminal
+ 
+   let lines =<< trim END
+       edit Xtestfile.txt
+       set undolevels=100 undofile
+       imap . <Cmd>write<CR>
+       write
+   END
+   call writefile(lines, 'Xtest_undo_after_write', 'D')
+   let buf = RunVimInTerminal('-S Xtest_undo_after_write', #{rows: 6})
+ 
+   call term_sendkeys(buf, "Otest.\<CR>boo!!!\<Esc>")
+   sleep 100m
+   call term_sendkeys(buf, "u")
+   call VerifyScreenDump(buf, 'Test_undo_after_write_1', {})
+ 
+   call term_sendkeys(buf, "u")
+   call VerifyScreenDump(buf, 'Test_undo_after_write_2', {})
+ 
+   call StopVimInTerminal(buf)
+   call delete('Xtestfile.txt')
+ endfunc
+ 
+ 
  " vim: shiftwidth=2 sts=2 expandtab
*** ../vim-9.0.1035/src/testdir/dumps/Test_undo_after_write_1.dump      
2022-12-08 21:48:56.772551376 +0000
--- src/testdir/dumps/Test_undo_after_write_1.dump      2022-12-08 
21:38:05.533014096 +0000
***************
*** 0 ****
--- 1,6 ----
+ |t+0&#ffffff0|e|s>t| @70
+ @75
+ |~+0#4040ff13&| @73
+ |~| @73
+ |~| @73
+ |1+0#0000000&| |l|i|n|e| |l|e|s@1|;| |b|e|f|o|r|e| |#|2| @1|0| 
|s|e|c|o|n|d|s| |a|g|o| @19|1|,|4| @10|A|l@1| 
*** ../vim-9.0.1035/src/testdir/dumps/Test_undo_after_write_2.dump      
2022-12-08 21:48:56.776551369 +0000
--- src/testdir/dumps/Test_undo_after_write_2.dump      2022-12-08 
21:38:06.681014280 +0000
***************
*** 0 ****
--- 1,6 ----
+ > +0&#ffffff0@74
+ |~+0#4040ff13&| @73
+ |~| @73
+ |~| @73
+ |~| @73
+ |2+0#0000000&| |f|e|w|e|r| |l|i|n|e|s|;| |b|e|f|o|r|e| |#|1| @1|1| 
|s|e|c|o|n|d| |a|g|o| @18|0|,|0|-|1| @8|A|l@1| 
*** ../vim-9.0.1035/src/testdir/dumps/Test_undo_after_write_2.vim       
2022-12-08 21:48:56.780551360 +0000
--- src/testdir/dumps/Test_undo_after_write_2.vim       2022-12-08 
21:46:07.980866824 +0000
***************
*** 0 ****
--- 1,2 ----
+ " Filter that changes the "1 second ago" message to "0 seconds ago".
+ 6s+|1| |s|e|c|o|n|d| |a|g|o| @18|+|0| |s|e|c|o|n|d|s| |a|g|o| @17|+e
*** ../vim-9.0.1035/src/version.c       2022-12-08 20:41:55.437288302 +0000
--- src/version.c       2022-12-08 21:48:42.172575195 +0000
***************
*** 697,698 ****
--- 697,700 ----
  {   /* Add new patch number below this line */
+ /**/
+     1036,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
10E. You start counting in hex.

 /// 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/20221208215007.799591C1742%40moolenaar.net.

Raspunde prin e-mail lui