From 620c8fdfe91a382982fafaa376acd722fe0df051 Mon Sep 17 00:00:00 2001 From: erw7 Date: Wed, 23 Sep 2020 10:33:18 +0900 Subject: [PATCH 1/3] extmark: fix decoration ploblems with extmark 54ce101 changed the way undo entries are created when adding decorations. This creates all sorts of problems.This change fixes the problem by reverting to the previous behavior. --- src/nvim/api/buffer.c | 4 ++-- src/nvim/extmark.c | 2 +- test/functional/api/highlight_spec.lua | 12 ++++++++++++ test/functional/ui/inccommand_spec.lua | 20 ++++++++++++++++++++ 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index e77870dcf3..2eeaeae522 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -1534,7 +1534,7 @@ Integer nvim_buf_add_highlight(Buffer buffer, ns_id = extmark_set(buf, ns_id, 0, (int)line, (colnr_T)col_start, end_line, (colnr_T)col_end, - decoration_hl(hl_id), kExtmarkUndo); + decoration_hl(hl_id), kExtmarkNoUndo); return src_id; } @@ -1664,7 +1664,7 @@ Integer nvim_buf_set_virtual_text(Buffer buffer, Decoration *decor = xcalloc(1, sizeof(*decor)); decor->virt_text = virt_text; - extmark_set(buf, ns_id, 0, (int)line, 0, -1, -1, decor, kExtmarkUndo); + extmark_set(buf, ns_id, 0, (int)line, 0, -1, -1, decor, kExtmarkNoUndo); return src_id; } diff --git a/src/nvim/extmark.c b/src/nvim/extmark.c index 17141f12fd..0de396fd1f 100644 --- a/src/nvim/extmark.c +++ b/src/nvim/extmark.c @@ -783,7 +783,7 @@ void bufhl_add_hl_pos_offset(buf_T *buf, } (void)extmark_set(buf, (uint64_t)src_id, 0, (int)lnum-1, hl_start, (int)lnum-1+end_off, hl_end, - decor, kExtmarkUndo); + decor, kExtmarkNoUndo); } } diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index a9d4c72d31..daf20c006c 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -7,6 +7,7 @@ local meths = helpers.meths local funcs = helpers.funcs local pcall_err = helpers.pcall_err local ok = helpers.ok +local assert_alive = helpers.assert_alive describe('API: highlight',function() local expected_rgb = { @@ -145,4 +146,15 @@ describe('API: highlight',function() eq({foreground=tonumber("0x888888"), background=tonumber("0x888888")}, meths.get_hl_by_name("Shrubbery", true)) end) + + it("nvim_buf_add_highlight to other buffer doesn't crash if undo is disabled #12873", function() + command('vsplit file') + local err, _ = pcall(meths.buf_set_option, 1, 'undofile', false) + eq(true, err) + err, _ = pcall(meths.buf_set_option, 1, 'undolevels', -1) + eq(true, err) + err, _ = pcall(meths.buf_add_highlight, 1, -1, 'Question', 0, 0, -1) + eq(true, err) + assert_alive() + end) end) diff --git a/test/functional/ui/inccommand_spec.lua b/test/functional/ui/inccommand_spec.lua index 74e85212c8..16c5477ee4 100644 --- a/test/functional/ui/inccommand_spec.lua +++ b/test/functional/ui/inccommand_spec.lua @@ -2750,6 +2750,26 @@ it(':substitute with inccommand, timer-induced :redraw #9777', function() ]]) end) +it(":substitute doesn't crash with inccommand, if undo is empty #12932", function() + local screen = Screen.new(10,5) + clear() + command('set undolevels=-1') + common_setup(screen, 'split', 'test') + feed(':%s/test') + sleep(100) + feed('/') + sleep(100) + feed('f') + screen:expect([[ + {12:f} | + {15:~ }| + {15:~ }| + {15:~ }| + :%s/test/f^ | + ]]) + assert_alive() +end) + it('long :%s/ with inccommand does not collapse cmdline', function() local screen = Screen.new(10,5) clear() From b2f9c2b6c19ce9b66bf278b487d3fe59bf26304f Mon Sep 17 00:00:00 2001 From: erw7 Date: Wed, 23 Sep 2020 10:55:13 +0900 Subject: [PATCH 2/3] undo: fix possibility of aborting --- src/nvim/undo.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/nvim/undo.c b/src/nvim/undo.c index 97018f6c02..903e57732f 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -3029,8 +3029,6 @@ u_header_T *u_force_get_undo_header(buf_T *buf) curbuf = buf; // Args are tricky: this means replace empty range by empty range.. u_savecommon(0, 1, 1, true); - curbuf = save_curbuf; - uhp = buf->b_u_curhead; if (!uhp) { uhp = buf->b_u_newhead; @@ -3038,6 +3036,7 @@ u_header_T *u_force_get_undo_header(buf_T *buf) abort(); } } + curbuf = save_curbuf; } return uhp; } From f1b39f91a5be7f3bf61b0e0d129dce49d51ff360 Mon Sep 17 00:00:00 2001 From: erw7 Date: Fri, 25 Sep 2020 09:26:44 +0900 Subject: [PATCH 3/3] extmark: Change nvim_buf_set_extmark to not create undo data --- src/nvim/api/buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 2eeaeae522..174f6e94a9 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -1420,7 +1420,7 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, } id = extmark_set(buf, (uint64_t)ns_id, id, - (int)line, (colnr_T)col, line2, col2, decor, kExtmarkUndo); + (int)line, (colnr_T)col, line2, col2, decor, kExtmarkNoUndo); return (Integer)id;