mirror of
https://github.com/neovim/neovim.git
synced 2024-12-23 20:55:18 -07:00
Merge pull request #5869 from hardenedapple/undojoin-curhead
Don't set `b_u_curhead` in `ex_undojoin()`
This commit is contained in:
commit
e8899178ec
@ -2551,20 +2551,20 @@ static void u_add_time(char_u *buf, size_t buflen, time_t tt)
|
||||
*/
|
||||
void ex_undojoin(exarg_T *eap)
|
||||
{
|
||||
if (curbuf->b_u_newhead == NULL)
|
||||
return; /* nothing changed before */
|
||||
if (curbuf->b_u_newhead == NULL) {
|
||||
return; // nothing changed before
|
||||
}
|
||||
if (curbuf->b_u_curhead != NULL) {
|
||||
EMSG(_("E790: undojoin is not allowed after undo"));
|
||||
return;
|
||||
}
|
||||
if (!curbuf->b_u_synced)
|
||||
return; /* already unsynced */
|
||||
if (get_undolevel() < 0)
|
||||
return; /* no entries, nothing to do */
|
||||
else {
|
||||
/* Go back to the last entry */
|
||||
curbuf->b_u_curhead = curbuf->b_u_newhead;
|
||||
curbuf->b_u_synced = false; /* no entries, nothing to do */
|
||||
if (!curbuf->b_u_synced) {
|
||||
return; // already unsynced
|
||||
}
|
||||
if (get_undolevel() < 0) {
|
||||
return; // no entries, nothing to do
|
||||
} else {
|
||||
curbuf->b_u_synced = false; // Append next change to last entry
|
||||
}
|
||||
}
|
||||
|
||||
|
38
test/functional/ex_cmds/undojoin_spec.lua
Normal file
38
test/functional/ex_cmds/undojoin_spec.lua
Normal file
@ -0,0 +1,38 @@
|
||||
local helpers = require('test.functional.helpers')(after_each)
|
||||
|
||||
local eq = helpers.eq
|
||||
local clear = helpers.clear
|
||||
local insert = helpers.insert
|
||||
local feed = helpers.feed
|
||||
local expect = helpers.expect
|
||||
local execute = helpers.execute
|
||||
local exc_exec = helpers.exc_exec
|
||||
|
||||
describe(':undojoin command', function()
|
||||
before_each(function()
|
||||
clear()
|
||||
insert([[
|
||||
Line of text 1
|
||||
Line of text 2]])
|
||||
execute('goto 1')
|
||||
end)
|
||||
it('joins changes in a buffer', function()
|
||||
execute('undojoin | delete')
|
||||
expect([[
|
||||
Line of text 2]])
|
||||
feed('u')
|
||||
expect([[
|
||||
]])
|
||||
end)
|
||||
it('does not corrupt undolist when connected with redo', function()
|
||||
feed('ixx<esc>')
|
||||
execute('undojoin | redo')
|
||||
expect([[
|
||||
xxLine of text 1
|
||||
Line of text 2]])
|
||||
end)
|
||||
it('does not raise an error when called twice', function()
|
||||
local ret = exc_exec('undojoin | undojoin')
|
||||
eq(0, ret)
|
||||
end)
|
||||
end)
|
Loading…
Reference in New Issue
Block a user