mirror of
https://github.com/hexedtech/codemp-nvim.git
synced 2024-11-22 23:44:55 +01:00
fix: wrap process_changes fn to provide controller
This commit is contained in:
parent
c1f5cb2d5b
commit
3f098185ca
1 changed files with 45 additions and 43 deletions
|
@ -24,7 +24,8 @@ local function detach(name)
|
||||||
require('codemp.window').update()
|
require('codemp.window').update()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function process_change(_, buf, tick, start_row, start_col, start_offset, old_end_row, old_end_col, old_end_byte_len, new_end_row, new_end_col, new_byte_len)
|
local function process_change_wrap(controller)
|
||||||
|
return function (_, buf, tick, start_row, start_col, start_offset, old_end_row, old_end_col, old_end_byte_len, new_end_row, new_end_col, new_byte_len)
|
||||||
if tick == ticks[buf] then return end
|
if tick == ticks[buf] then return end
|
||||||
if id_buffer_map[buf] == nil then return true end -- unregister callback handler
|
if id_buffer_map[buf] == nil then return true end -- unregister callback handler
|
||||||
if CODEMP.config.debug then print(string.format(
|
if CODEMP.config.debug then print(string.format(
|
||||||
|
@ -68,6 +69,7 @@ local function process_change(_, buf, tick, start_row, start_col, start_offset,
|
||||||
start_idx = start_offset, end_idx = end_offset, content = change_content
|
start_idx = start_offset, end_idx = end_offset, content = change_content
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
---@class AttachOptions
|
---@class AttachOptions
|
||||||
---@field content? string if provided, set this as content after attaching
|
---@field content? string if provided, set this as content after attaching
|
||||||
|
@ -127,7 +129,7 @@ local function attach(name, opts)
|
||||||
|
|
||||||
-- hook serverbound callbacks
|
-- hook serverbound callbacks
|
||||||
-- TODO breaks when deleting whole lines at buffer end
|
-- TODO breaks when deleting whole lines at buffer end
|
||||||
vim.api.nvim_buf_attach(buffer, false, { on_bytes = process_change })
|
vim.api.nvim_buf_attach(buffer, false, { on_bytes = process_change_wrap(controller) })
|
||||||
|
|
||||||
local lock = false
|
local lock = false
|
||||||
local async = vim.loop.new_async(vim.schedule_wrap(function ()
|
local async = vim.loop.new_async(vim.schedule_wrap(function ()
|
||||||
|
|
Loading…
Reference in a new issue