aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/change.c3
-rw-r--r--src/nvim/eval.c3
-rw-r--r--test/functional/lua/buffer_updates_spec.lua25
3 files changed, 26 insertions, 5 deletions
diff --git a/src/nvim/change.c b/src/nvim/change.c
index b8bc08b747..8bf02385ef 100644
--- a/src/nvim/change.c
+++ b/src/nvim/change.c
@@ -362,8 +362,7 @@ void changed_bytes(linenr_T lnum, colnr_T col)
/// insert/delete bytes at column
///
/// Like changed_bytes() but also adjust extmark for "new" bytes.
-/// When "new" is negative text was deleted.
-static void inserted_bytes(linenr_T lnum, colnr_T col, int old, int new)
+void inserted_bytes(linenr_T lnum, colnr_T col, int old, int new)
{
if (curbuf_splice_pending == 0) {
extmark_splice_cols(curbuf, (int)lnum-1, col, old, new, kExtmarkUndo);
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 32830c5d7f..b395d7bb8a 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -6962,9 +6962,10 @@ void set_buffer_lines(buf_T *buf, linenr_T lnum_arg, bool append,
if (!append && lnum <= curbuf->b_ml.ml_line_count) {
// Existing line, replace it.
+ int old_len = (int)STRLEN(ml_get(lnum));
if (u_savesub(lnum) == OK
&& ml_replace(lnum, (char_u *)line, true) == OK) {
- changed_bytes(lnum, 0);
+ inserted_bytes(lnum, 0, old_len, STRLEN(line));
if (is_curbuf && lnum == curwin->w_cursor.lnum) {
check_cursor_col();
}
diff --git a/test/functional/lua/buffer_updates_spec.lua b/test/functional/lua/buffer_updates_spec.lua
index 5be47070a7..cc5db2a355 100644
--- a/test/functional/lua/buffer_updates_spec.lua
+++ b/test/functional/lua/buffer_updates_spec.lua
@@ -5,6 +5,7 @@ local inspect = require'vim.inspect'
local command = helpers.command
local meths = helpers.meths
+local funcs = helpers.funcs
local clear = helpers.clear
local eq = helpers.eq
local fail = helpers.fail
@@ -273,7 +274,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
local events = exec_lua("return get_events(...)" )
if not pcall(eq, expected, events) then
- local msg = 'unexpected byte updates received.\n\nBABBLA MER \n\n'
+ local msg = 'unexpected byte updates received.\n\n'
msg = msg .. 'received events:\n'
for _, e in ipairs(events) do
@@ -300,7 +301,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') .. '\n'
- eq(string.len(bytes), string.len(shadowbytes), shadowbytes)
+ eq(string.len(bytes), string.len(shadowbytes), '\non_bytes: total bytecount of buffer is wrong')
for i = 1, string.len(shadowbytes) do
local shadowbyte = string.sub(shadowbytes, i, i)
if shadowbyte ~= '\255' then
@@ -355,6 +356,26 @@ describe('lua: nvim_buf_attach on_bytes', function()
{ "test1", "bytes", 1, 5, 7, 4, 118, 0, 0, 0, 1, 4, 5 };
}
end)
+
+ it('setline(num, line)', function()
+ local check_events = setup_eventcheck(verify)
+ funcs.setline(2, "babla")
+ check_events {
+ { "test1", "bytes", 1, 3, 1, 0, 16, 0, 15, 15, 0, 5, 5 };
+ }
+
+ funcs.setline(2, {"foo", "bar"})
+ check_events {
+ { "test1", "bytes", 1, 4, 1, 0, 16, 0, 5, 5, 0, 3, 3 };
+ { "test1", "bytes", 1, 5, 2, 0, 20, 0, 15, 15, 0, 3, 3 };
+ }
+
+ local buf_len = meths.buf_line_count(0)
+ funcs.setline(buf_len + 1, "baz")
+ check_events {
+ { "test1", "bytes", 1, 6, 7, 0, 90, 0, 0, 0, 1, 0, 4 };
+ }
+ end)
end
describe('(with verify) handles', function()