From 7d171b1c48377aa5724d3bed0f497bf729b39b1c Mon Sep 17 00:00:00 2001 From: Anton Adamansky Date: Mon, 5 Jul 2021 23:30:07 +0700 Subject: fix(buffer_updates): make `lockmarks` not affect extmarks and buffer updates. fixes #12861 Now mark_adjust() will trigger appropriate buf_updates_send_splice() called by extmark_adjust() --- src/nvim/mark.c | 7 +++-- test/functional/lua/buffer_updates_spec.lua | 48 ++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/src/nvim/mark.c b/src/nvim/mark.c index edec85c0b2..835c2adbe5 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -1036,9 +1036,10 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2, long amount, lo } sign_mark_adjust(line1, line2, amount, amount_after); - if (op != kExtmarkNOOP) { - extmark_adjust(curbuf, line1, line2, amount, amount_after, op); - } + } + + if (op != kExtmarkNOOP) { + extmark_adjust(curbuf, line1, line2, amount, amount_after, op); } // previous context mark diff --git a/test/functional/lua/buffer_updates_spec.lua b/test/functional/lua/buffer_updates_spec.lua index 42b3d86eb0..f2740feb10 100644 --- a/test/functional/lua/buffer_updates_spec.lua +++ b/test/functional/lua/buffer_updates_spec.lua @@ -349,7 +349,12 @@ describe('lua: nvim_buf_attach on_bytes', function() end local text = meths.buf_get_lines(0, 0, -1, true) - local bytes = table.concat(text, '\n') .. '\n' + local bytes = table.concat(text, '\n') + if #text ~= 1 or #bytes ~= 0 then + -- Not empty buffer. + -- Append '\n' only if buffer is not empty, see nvim_buf_get_lines(). + bytes = bytes .. '\n' + end eq(string.len(bytes), string.len(shadowbytes), '\non_bytes: total bytecount of buffer is wrong') for i = 1, string.len(shadowbytes) do @@ -1088,6 +1093,47 @@ describe('lua: nvim_buf_attach on_bytes', function() } end) + local function test_lockmarks(mode) + if not mode then mode = "" end + it("test_lockmarks " .. mode .. " %delete _", function() + local check_events = setup_eventcheck(verify, {"AAA", "BBB", "CCC"}) + + command(mode .. " %delete _") + check_events { + { "test1", "bytes", 1, 3, 0, 0, 0, 3, 0, 12, 0, 0, 0 }; + } + end) + + it("test_lockmarks " .. mode .. " append()", function() + local check_events = setup_eventcheck(verify) + + command(mode .. " call append(0, 'CCC')") + check_events { + { "test1", "bytes", 1, 2, 0, 0, 0, 0, 0, 0, 1, 0, 4 }; + } + + command(mode .. " call append(1, 'BBBB')") + check_events { + { "test1", "bytes", 1, 3, 1, 0, 4, 0, 0, 0, 1, 0, 5 }; + } + + command(mode .. " call append(2, '')") + check_events { + { "test1", "bytes", 1, 4, 2, 0, 9, 0, 0, 0, 1, 0, 1 }; + } + + command(mode .. " $delete _") + check_events { + { "test1", "bytes", 1, 5, 3, 0, 10, 1, 0, 1, 0, 0, 0 }; + } + + eq("CCC|BBBB|", table.concat(meths.buf_get_lines(0, 0, -1, true), "|")) + end) + end + + test_lockmarks() + test_lockmarks "lockmarks" + teardown(function() os.remove "Xtest-reload" os.remove "Xtest-undofile" -- cgit From 54b2c6800e9809b749381890da0f98f63f5fe53b Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Thu, 7 Oct 2021 19:06:09 +0200 Subject: fix(buffer_updates): cleanup test behavior --- test/functional/lua/buffer_updates_spec.lua | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/test/functional/lua/buffer_updates_spec.lua b/test/functional/lua/buffer_updates_spec.lua index f2740feb10..83ed7394b0 100644 --- a/test/functional/lua/buffer_updates_spec.lua +++ b/test/functional/lua/buffer_updates_spec.lua @@ -349,12 +349,7 @@ describe('lua: nvim_buf_attach on_bytes', function() end local text = meths.buf_get_lines(0, 0, -1, true) - local bytes = table.concat(text, '\n') - if #text ~= 1 or #bytes ~= 0 then - -- Not empty buffer. - -- Append '\n' only if buffer is not empty, see nvim_buf_get_lines(). - bytes = bytes .. '\n' - end + local bytes = table.concat(text, '\n') .. '\n' eq(string.len(bytes), string.len(shadowbytes), '\non_bytes: total bytecount of buffer is wrong') for i = 1, string.len(shadowbytes) do @@ -1094,17 +1089,17 @@ describe('lua: nvim_buf_attach on_bytes', function() end) local function test_lockmarks(mode) - if not mode then mode = "" end - it("test_lockmarks " .. mode .. " %delete _", function() + local description = (mode ~= "") and mode or "(baseline)" + it("test_lockmarks " .. description .. " %delete _", function() local check_events = setup_eventcheck(verify, {"AAA", "BBB", "CCC"}) command(mode .. " %delete _") check_events { - { "test1", "bytes", 1, 3, 0, 0, 0, 3, 0, 12, 0, 0, 0 }; + { "test1", "bytes", 1, 3, 0, 0, 0, 3, 0, 12, 1, 0, 1 }; } end) - it("test_lockmarks " .. mode .. " append()", function() + it("test_lockmarks " .. description .. " append()", function() local check_events = setup_eventcheck(verify) command(mode .. " call append(0, 'CCC')") @@ -1131,7 +1126,8 @@ describe('lua: nvim_buf_attach on_bytes', function() end) end - test_lockmarks() + -- check that behavior is identical with and without "lockmarks" + test_lockmarks "" test_lockmarks "lockmarks" teardown(function() -- cgit