fix: apply received changes granularly

This commit is contained in:
əlemi 2023-11-17 03:55:45 +01:00
parent f69d91b9f6
commit 67b9389c5b

View file

@ -79,9 +79,29 @@ local function buffer_get_content(buf)
return table.concat(lines, '\n') return table.concat(lines, '\n')
end end
local function buffer_set_content(buf, content) -- local function buffer_set_content(buf, content)
local lines = split_without_trim(content, "\n") -- local lines = split_without_trim(content, "\n")
vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines) -- vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines)
-- end
local function buffer_replace_content(buffer, first, last, content)
-- TODO send help it works but why is lost knowledge
local start_row = vim.fn.byte2line(first + 1) - 1
if start_row < 0 then start_row = 0 end
local start_row_byte = vim.fn.line2byte(start_row + 1) - 1
if start_row_byte < 0 then start_row_byte = 0 end
local end_row = vim.fn.byte2line(last + 1) - 1
if end_row < 0 then end_row = 0 end
local end_row_byte = vim.fn.line2byte(end_row + 1) - 1
if end_row_byte < 0 then end_row_byte = 0 end
vim.api.nvim_buf_set_text(
buffer,
start_row,
first - start_row_byte,
end_row,
last - end_row_byte,
vim.fn.split(content, '\n', true)
)
end end
local function multiline_highlight(buf, ns, group, start, fini) local function multiline_highlight(buf, ns, group, start, fini)
@ -206,7 +226,7 @@ vim.api.nvim_create_user_command(
-- hook clientbound callbacks -- hook clientbound callbacks
register_controller_handler(args.args, controller, function(event) register_controller_handler(args.args, controller, function(event)
codemp_changed_tick = vim.api.nvim_buf_get_changedtick(buffer) + 1 codemp_changed_tick = vim.api.nvim_buf_get_changedtick(buffer) + 1
buffer_set_content(buffer, event.content) buffer_replace_content(buffer, event.first, event.last, event.content)
end) end)
print(" ++ joined workspace " .. args.args) print(" ++ joined workspace " .. args.args)