mirror of
https://github.com/neovim/neovim.git
synced 2025-09-30 15:08:35 +00:00
fix(inccommand): don't set an invalid 'undolevels' value
Problem: Cannot break undo by setting 'undolevels' to itself in
'inccommand' preview callback.
Solution: Don't set an invalid 'undolevels' value.
Co-authored-by: Michael Henry <drmikehenry@drmikehenry.com>
(cherry picked from commit 7c5e7d831a
)
This commit is contained in:

committed by
github-actions[bot]
![github-actions[bot]](/assets/img/avatar_default.png)
parent
df63474930
commit
06ec1a49d7
@@ -2352,7 +2352,7 @@ static void cmdpreview_prepare(CpInfo *cpinfo)
|
|||||||
pmap_put(ptr_t)(&saved_bufs, buf, NULL);
|
pmap_put(ptr_t)(&saved_bufs, buf, NULL);
|
||||||
|
|
||||||
u_clearall(buf);
|
u_clearall(buf);
|
||||||
buf->b_p_ul = LONG_MAX; // Make sure we can undo all changes
|
buf->b_p_ul = INT_MAX; // Make sure we can undo all changes
|
||||||
}
|
}
|
||||||
|
|
||||||
CpWinInfo cp_wininfo;
|
CpWinInfo cp_wininfo;
|
||||||
|
@@ -239,7 +239,8 @@ describe("'inccommand' for user commands", function()
|
|||||||
[1] = {background = Screen.colors.Yellow1},
|
[1] = {background = Screen.colors.Yellow1},
|
||||||
[2] = {foreground = Screen.colors.Blue1, bold = true},
|
[2] = {foreground = Screen.colors.Blue1, bold = true},
|
||||||
[3] = {reverse = true},
|
[3] = {reverse = true},
|
||||||
[4] = {reverse = true, bold = true}
|
[4] = {reverse = true, bold = true},
|
||||||
|
[5] = {foreground = Screen.colors.Blue},
|
||||||
})
|
})
|
||||||
screen:attach()
|
screen:attach()
|
||||||
exec_lua(setup_replace_cmd)
|
exec_lua(setup_replace_cmd)
|
||||||
@@ -458,9 +459,8 @@ describe("'inccommand' for user commands", function()
|
|||||||
assert_alive()
|
assert_alive()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('breaking undo chain in Insert mode works properly #20248', function()
|
local function test_preview_break_undo()
|
||||||
command('set inccommand=nosplit')
|
command('set inccommand=nosplit')
|
||||||
command('inoremap . .<C-G>u')
|
|
||||||
exec_lua([[
|
exec_lua([[
|
||||||
vim.api.nvim_create_user_command('Test', function() end, {
|
vim.api.nvim_create_user_command('Test', function() end, {
|
||||||
nargs = 1,
|
nargs = 1,
|
||||||
@@ -490,6 +490,26 @@ describe("'inccommand' for user commands", function()
|
|||||||
{2:~ }|
|
{2:~ }|
|
||||||
:Test a.a.a.a.^ |
|
:Test a.a.a.a.^ |
|
||||||
]])
|
]])
|
||||||
|
feed('<C-V><Esc>u')
|
||||||
|
screen:expect([[
|
||||||
|
text on line 1 |
|
||||||
|
more text on line 2 |
|
||||||
|
oh no, even more text |
|
||||||
|
will the text ever stop |
|
||||||
|
oh well |
|
||||||
|
did the text stop |
|
||||||
|
why won't it stop |
|
||||||
|
make the text stop |
|
||||||
|
a.a.a. |
|
||||||
|
{2:~ }|
|
||||||
|
{2:~ }|
|
||||||
|
{2:~ }|
|
||||||
|
{2:~ }|
|
||||||
|
{2:~ }|
|
||||||
|
{2:~ }|
|
||||||
|
{2:~ }|
|
||||||
|
:Test a.a.a.a.{5:^[}u^ |
|
||||||
|
]])
|
||||||
feed('<Esc>')
|
feed('<Esc>')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
text on line 1 |
|
text on line 1 |
|
||||||
@@ -510,6 +530,18 @@ describe("'inccommand' for user commands", function()
|
|||||||
{2:~ }|
|
{2:~ }|
|
||||||
|
|
|
|
||||||
]])
|
]])
|
||||||
|
end
|
||||||
|
|
||||||
|
describe('breaking undo chain in Insert mode works properly', function()
|
||||||
|
it('when using i_CTRL-G_u #20248', function()
|
||||||
|
command('inoremap . .<C-G>u')
|
||||||
|
test_preview_break_undo()
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('when setting &l:undolevels to itself #24575', function()
|
||||||
|
command('inoremap . .<Cmd>let &l:undolevels = &l:undolevels<CR>')
|
||||||
|
test_preview_break_undo()
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user