case K_COMMAND: // <Cmd>command<CR>
case K_SCRIPT_COMMAND: // <ScriptCmd>command<CR>
- do_cmdkey_command(c, 0);
+ {
+ do_cmdkey_command(c, 0);
+
#ifdef FEAT_TERMINAL
- if (term_use_loop())
- // Started a terminal that gets the input, exit Insert mode.
- goto doESCkey;
+ 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.
" undo-able pieces. Do that by setting 'undolevels'.
" Also tests :earlier and :later.
+source check.vim
+source screendump.vim
+
func Test_undotree()
new
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