mirror of
https://github.com/neovim/neovim.git
synced 2024-12-20 03:05:11 -07:00
Merge pull request #12917 from bfredl/bytes_setline
buf_attach: fix buffer updates with setline()
This commit is contained in:
commit
aa98527ce7
@ -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);
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user