mirror of
https://github.com/neovim/neovim.git
synced 2025-09-05 19:08:15 +00:00
fix(inccommand): don't save information of a buffer twice
Problem: 'inccommand' doesn't restore 'undolevels' properly for a buffer shown in multiple windows. Solution: Don't save information of a buffer twice.
This commit is contained in:
@@ -2328,6 +2328,8 @@ static void cmdpreview_restore_undo(const CpUndoInfo *cp_undoinfo, buf_T *buf)
|
||||
static void cmdpreview_prepare(CpInfo *cpinfo)
|
||||
FUNC_ATTR_NONNULL_ALL
|
||||
{
|
||||
PMap(ptr_t) saved_bufs = MAP_INIT;
|
||||
|
||||
kv_init(cpinfo->buf_info);
|
||||
kv_init(cpinfo->win_info);
|
||||
|
||||
@@ -2339,19 +2341,19 @@ static void cmdpreview_prepare(CpInfo *cpinfo)
|
||||
continue;
|
||||
}
|
||||
|
||||
CpBufInfo cp_bufinfo;
|
||||
cp_bufinfo.buf = buf;
|
||||
if (!pmap_has(ptr_t)(&saved_bufs, buf)) {
|
||||
CpBufInfo cp_bufinfo;
|
||||
cp_bufinfo.buf = buf;
|
||||
cp_bufinfo.save_b_p_ul = buf->b_p_ul;
|
||||
cp_bufinfo.save_b_changed = buf->b_changed;
|
||||
cp_bufinfo.save_changedtick = buf_get_changedtick(buf);
|
||||
cmdpreview_save_undo(&cp_bufinfo.undo_info, buf);
|
||||
kv_push(cpinfo->buf_info, cp_bufinfo);
|
||||
pmap_put(ptr_t)(&saved_bufs, buf, NULL);
|
||||
|
||||
cp_bufinfo.save_b_p_ul = buf->b_p_ul;
|
||||
cp_bufinfo.save_b_changed = buf->b_changed;
|
||||
cp_bufinfo.save_changedtick = buf_get_changedtick(buf);
|
||||
|
||||
cmdpreview_save_undo(&cp_bufinfo.undo_info, buf);
|
||||
u_clearall(buf);
|
||||
|
||||
kv_push(cpinfo->buf_info, cp_bufinfo);
|
||||
|
||||
buf->b_p_ul = LONG_MAX; // Make sure we can undo all changes
|
||||
u_clearall(buf);
|
||||
buf->b_p_ul = LONG_MAX; // Make sure we can undo all changes
|
||||
}
|
||||
|
||||
CpWinInfo cp_wininfo;
|
||||
cp_wininfo.win = win;
|
||||
@@ -2370,6 +2372,8 @@ static void cmdpreview_prepare(CpInfo *cpinfo)
|
||||
win->w_p_cuc = false; // Disable 'cursorcolumn' so it doesn't mess up the highlights
|
||||
}
|
||||
|
||||
pmap_destroy(ptr_t)(&saved_bufs);
|
||||
|
||||
cpinfo->save_hls = p_hls;
|
||||
cpinfo->save_cmdmod = cmdmod;
|
||||
win_size_save(&cpinfo->save_view);
|
||||
@@ -2426,6 +2430,7 @@ static void cmdpreview_restore_state(CpInfo *cpinfo)
|
||||
// Clear preview highlights.
|
||||
extmark_clear(buf, (uint32_t)cmdpreview_ns, 0, 0, MAXLNUM, MAXCOL);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < cpinfo->win_info.size; i++) {
|
||||
CpWinInfo cp_wininfo = cpinfo->win_info.items[i];
|
||||
win_T *win = cp_wininfo.win;
|
||||
|
@@ -2,7 +2,6 @@ local helpers = require('test.functional.helpers')(after_each)
|
||||
local Screen = require('test.functional.ui.screen')
|
||||
local clear = helpers.clear
|
||||
local command = helpers.command
|
||||
local curbufmeths = helpers.curbufmeths
|
||||
local eq = helpers.eq
|
||||
local eval = helpers.eval
|
||||
local feed_command = helpers.feed_command
|
||||
@@ -175,11 +174,14 @@ describe(":substitute, 'inccommand' preserves", function()
|
||||
it("'undolevels' (inccommand="..case..")", function()
|
||||
feed_command("set undolevels=139")
|
||||
feed_command("setlocal undolevels=34")
|
||||
feed_command("split") -- Show the buffer in multiple windows
|
||||
feed_command("set inccommand=" .. case)
|
||||
insert("as")
|
||||
feed(":%s/as/glork/<enter>")
|
||||
eq(meths.get_option('undolevels'), 139)
|
||||
eq(curbufmeths.get_option('undolevels'), 34)
|
||||
feed(":%s/as/glork/")
|
||||
poke_eventloop()
|
||||
feed("<enter>")
|
||||
eq(meths.get_option_value('undolevels', {scope='global'}), 139)
|
||||
eq(meths.get_option_value('undolevels', {buf=0}), 34)
|
||||
end)
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user