mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
Merge pull request #21348 from zeertzjq/vim-9.0.1036
vim-patch:9.0.1036: undo misbehaves when writing from an insert mode mapping
This commit is contained in:
@@ -908,6 +908,12 @@ check_pum:
|
|||||||
}
|
}
|
||||||
pum_want.active = false;
|
pum_want.active = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (curbuf->b_u_synced) {
|
||||||
|
// The K_EVENT, K_COMMAND, or K_LUA caused undo to be synced.
|
||||||
|
// Need to save the line for undo before inserting the next char.
|
||||||
|
ins_need_undo = true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case K_HOME: // <Home>
|
case K_HOME: // <Home>
|
||||||
|
@@ -3,6 +3,9 @@
|
|||||||
" undo-able pieces. Do that by setting 'undolevels'.
|
" undo-able pieces. Do that by setting 'undolevels'.
|
||||||
" Also tests :earlier and :later.
|
" Also tests :earlier and :later.
|
||||||
|
|
||||||
|
source check.vim
|
||||||
|
source screendump.vim
|
||||||
|
|
||||||
func Test_undotree()
|
func Test_undotree()
|
||||||
new
|
new
|
||||||
|
|
||||||
@@ -773,4 +776,30 @@ func Test_undo_mark()
|
|||||||
bwipe!
|
bwipe!
|
||||||
endfunc
|
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: shiftwidth=2 sts=2 expandtab
|
||||||
|
@@ -9,6 +9,8 @@ local feed = helpers.feed
|
|||||||
local feed_command = helpers.feed_command
|
local feed_command = helpers.feed_command
|
||||||
local insert = helpers.insert
|
local insert = helpers.insert
|
||||||
local funcs = helpers.funcs
|
local funcs = helpers.funcs
|
||||||
|
local exec = helpers.exec
|
||||||
|
local exec_lua = helpers.exec_lua
|
||||||
|
|
||||||
local function lastmessage()
|
local function lastmessage()
|
||||||
local messages = funcs.split(funcs.execute('messages'), '\n')
|
local messages = funcs.split(funcs.execute('messages'), '\n')
|
||||||
@@ -67,6 +69,79 @@ describe('u CTRL-R g- g+', function()
|
|||||||
undo_and_redo(4, 'u', '<C-r>', '1')
|
undo_and_redo(4, 'u', '<C-r>', '1')
|
||||||
undo_and_redo(4, 'g-', 'g+', '1')
|
undo_and_redo(4, 'g-', 'g+', '1')
|
||||||
end)
|
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 <Cmd> mapping', function()
|
||||||
|
command('imap . <Cmd>write<CR>')
|
||||||
|
feed('Otest.<CR>boo!!!<Esc>')
|
||||||
|
expect([[
|
||||||
|
test
|
||||||
|
boo!!!
|
||||||
|
]])
|
||||||
|
|
||||||
|
feed('u')
|
||||||
|
expect([[
|
||||||
|
test
|
||||||
|
]])
|
||||||
|
|
||||||
|
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.<CR>boo!!!<Esc>')
|
||||||
|
expect([[
|
||||||
|
test
|
||||||
|
boo!!!
|
||||||
|
]])
|
||||||
|
|
||||||
|
feed('u')
|
||||||
|
expect([[
|
||||||
|
test
|
||||||
|
]])
|
||||||
|
|
||||||
|
feed('u')
|
||||||
|
expect('')
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('using RPC call', function()
|
||||||
|
feed('Otest')
|
||||||
|
command('write')
|
||||||
|
feed('<CR>boo!!!<Esc>')
|
||||||
|
expect([[
|
||||||
|
test
|
||||||
|
boo!!!
|
||||||
|
]])
|
||||||
|
|
||||||
|
feed('u')
|
||||||
|
expect([[
|
||||||
|
test
|
||||||
|
]])
|
||||||
|
|
||||||
|
feed('u')
|
||||||
|
expect('')
|
||||||
|
end)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe(':undo! command', function()
|
describe(':undo! command', function()
|
||||||
|
Reference in New Issue
Block a user