From 70d6c335b17cf166760457e3673aa61098ef0e66 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 9 Dec 2022 06:35:29 +0800 Subject: vim-patch:9.0.1036: undo misbehaves when writing from an insert mode mapping Problem: Undo misbehaves when writing from an insert mode mapping. Solution: Sync undo when writing. (closes vim/vim#11674) https://github.com/vim/vim/commit/3f8f82772313af9f2417b06651f30988b63e1c96 Co-authored-by: Bram Moolenaar --- test/functional/editor/undo_spec.lua | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'test/functional/editor') diff --git a/test/functional/editor/undo_spec.lua b/test/functional/editor/undo_spec.lua index a041428cdc..6f9c4506fc 100644 --- a/test/functional/editor/undo_spec.lua +++ b/test/functional/editor/undo_spec.lua @@ -9,6 +9,7 @@ local feed = helpers.feed local feed_command = helpers.feed_command local insert = helpers.insert local funcs = helpers.funcs +local exec = helpers.exec local function lastmessage() local messages = funcs.split(funcs.execute('messages'), '\n') @@ -67,6 +68,40 @@ describe('u CTRL-R g- g+', function() undo_and_redo(4, 'u', '', '1') undo_and_redo(4, 'g-', 'g+', '1') end) + + describe('undo works correctly when writing in Insert mode', function() + before_each(function() + exec([[ + edit Xtestfile.txt + set undolevels=100 undofile + write + ]]) + end) + + after_each(function() + command('bwipe!') + os.remove('Xtestfile.txt') + os.remove('Xtestfile.txt.un~') + end) + + -- oldtest: Test_undo_after_write() + it('using mapping', function() + command('imap . write') + feed('Otest.boo!!!') + expect([[ + test + boo!!! + ]]) + + feed('u') + expect([[ + test + ]]) + + feed('u') + expect('') + end) + end) end) describe(':undo! command', function() -- cgit From 95044991e618827924ac47aeae8bd0eacc775f58 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 9 Dec 2022 06:57:18 +0800 Subject: test(undo_spec): add more tests for writing in Insert mode --- test/functional/editor/undo_spec.lua | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'test/functional/editor') diff --git a/test/functional/editor/undo_spec.lua b/test/functional/editor/undo_spec.lua index 6f9c4506fc..d66ab352ef 100644 --- a/test/functional/editor/undo_spec.lua +++ b/test/functional/editor/undo_spec.lua @@ -10,6 +10,7 @@ local feed_command = helpers.feed_command local insert = helpers.insert local funcs = helpers.funcs local exec = helpers.exec +local exec_lua = helpers.exec_lua local function lastmessage() local messages = funcs.split(funcs.execute('messages'), '\n') @@ -101,6 +102,45 @@ describe('u CTRL-R g- g+', function() feed('u') expect('') end) + + it('using Lua mapping', function() + exec_lua([[ + vim.api.nvim_set_keymap('i', '.', '', {callback = function() + vim.cmd('write') + end}) + ]]) + feed('Otest.boo!!!') + expect([[ + test + boo!!! + ]]) + + feed('u') + expect([[ + test + ]]) + + feed('u') + expect('') + end) + + it('using RPC call', function() + feed('Otest') + command('write') + feed('boo!!!') + expect([[ + test + boo!!! + ]]) + + feed('u') + expect([[ + test + ]]) + + feed('u') + expect('') + end) end) end) -- cgit