mirror of
https://github.com/neovim/neovim.git
synced 2025-10-15 14:26:07 +00:00
fix(inccommand): deal with unsynced undo (#20041)
This commit is contained in:
@@ -136,6 +136,7 @@ typedef struct cmdpreview_win_info {
|
|||||||
|
|
||||||
typedef struct cmdpreview_buf_info {
|
typedef struct cmdpreview_buf_info {
|
||||||
buf_T *buf;
|
buf_T *buf;
|
||||||
|
bool save_b_u_synced;
|
||||||
time_t save_b_u_time_cur;
|
time_t save_b_u_time_cur;
|
||||||
long save_b_u_seq_cur;
|
long save_b_u_seq_cur;
|
||||||
u_header_T *save_b_u_newhead;
|
u_header_T *save_b_u_newhead;
|
||||||
@@ -2131,6 +2132,7 @@ static void cmdpreview_prepare(CpInfo *cpinfo)
|
|||||||
CpBufInfo cp_bufinfo;
|
CpBufInfo cp_bufinfo;
|
||||||
cp_bufinfo.buf = buf;
|
cp_bufinfo.buf = buf;
|
||||||
|
|
||||||
|
cp_bufinfo.save_b_u_synced = buf->b_u_synced;
|
||||||
cp_bufinfo.save_b_u_time_cur = buf->b_u_time_cur;
|
cp_bufinfo.save_b_u_time_cur = buf->b_u_time_cur;
|
||||||
cp_bufinfo.save_b_u_seq_cur = buf->b_u_seq_cur;
|
cp_bufinfo.save_b_u_seq_cur = buf->b_u_seq_cur;
|
||||||
cp_bufinfo.save_b_u_newhead = buf->b_u_newhead;
|
cp_bufinfo.save_b_u_newhead = buf->b_u_newhead;
|
||||||
@@ -2168,6 +2170,8 @@ static void cmdpreview_prepare(CpInfo *cpinfo)
|
|||||||
cmdmod.cmod_split = 0; // Disable :leftabove/botright modifiers
|
cmdmod.cmod_split = 0; // Disable :leftabove/botright modifiers
|
||||||
cmdmod.cmod_tab = 0; // Disable :tab modifier
|
cmdmod.cmod_tab = 0; // Disable :tab modifier
|
||||||
cmdmod.cmod_flags |= CMOD_NOSWAPFILE; // Disable swap for preview buffer
|
cmdmod.cmod_flags |= CMOD_NOSWAPFILE; // Disable swap for preview buffer
|
||||||
|
|
||||||
|
u_sync(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore the state of buffers and windows before command preview.
|
// Restore the state of buffers and windows before command preview.
|
||||||
@@ -2200,6 +2204,11 @@ static void cmdpreview_restore_state(CpInfo *cpinfo)
|
|||||||
buf->b_u_newhead = cp_bufinfo.save_b_u_newhead;
|
buf->b_u_newhead = cp_bufinfo.save_b_u_newhead;
|
||||||
buf->b_u_time_cur = cp_bufinfo.save_b_u_time_cur;
|
buf->b_u_time_cur = cp_bufinfo.save_b_u_time_cur;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (buf->b_u_curhead == NULL) {
|
||||||
|
buf->b_u_synced = cp_bufinfo.save_b_u_synced;
|
||||||
|
}
|
||||||
|
|
||||||
if (cp_bufinfo.save_changedtick != buf_get_changedtick(buf)) {
|
if (cp_bufinfo.save_changedtick != buf_get_changedtick(buf)) {
|
||||||
buf_set_changedtick(buf, cp_bufinfo.save_changedtick);
|
buf_set_changedtick(buf, cp_bufinfo.save_changedtick);
|
||||||
}
|
}
|
||||||
|
@@ -3047,6 +3047,43 @@ it(":substitute doesn't crash with inccommand, if undo is empty #12932", functio
|
|||||||
assert_alive()
|
assert_alive()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it(':substitute with inccommand works properly if undo is not synced #20029', function()
|
||||||
|
local screen = Screen.new(30, 6)
|
||||||
|
clear()
|
||||||
|
common_setup(screen, 'nosplit', 'foo\nbar\nbaz')
|
||||||
|
meths.set_keymap('x', '<F2>', '<Esc>`<Oaaaaa asdf<Esc>`>obbbbb asdf<Esc>V`<k:s/asdf/', {})
|
||||||
|
feed('gg0<C-V>lljj<F2>')
|
||||||
|
screen:expect([[
|
||||||
|
aaaaa |
|
||||||
|
foo |
|
||||||
|
bar |
|
||||||
|
baz |
|
||||||
|
bbbbb |
|
||||||
|
:'<,'>s/asdf/^ |
|
||||||
|
]])
|
||||||
|
feed('hjkl')
|
||||||
|
screen:expect([[
|
||||||
|
aaaaa {12:hjkl} |
|
||||||
|
foo |
|
||||||
|
bar |
|
||||||
|
baz |
|
||||||
|
bbbbb {12:hjkl} |
|
||||||
|
:'<,'>s/asdf/hjkl^ |
|
||||||
|
]])
|
||||||
|
feed('<CR>')
|
||||||
|
expect([[
|
||||||
|
aaaaa hjkl
|
||||||
|
foo
|
||||||
|
bar
|
||||||
|
baz
|
||||||
|
bbbbb hjkl]])
|
||||||
|
feed('u')
|
||||||
|
expect([[
|
||||||
|
foo
|
||||||
|
bar
|
||||||
|
baz]])
|
||||||
|
end)
|
||||||
|
|
||||||
it('long :%s/ with inccommand does not collapse cmdline', function()
|
it('long :%s/ with inccommand does not collapse cmdline', function()
|
||||||
local screen = Screen.new(10,5)
|
local screen = Screen.new(10,5)
|
||||||
clear()
|
clear()
|
||||||
|
Reference in New Issue
Block a user