mirror of
https://github.com/hexedtech/codemp-nvim.git
synced 2024-11-22 15:34:53 +01:00
fix: track ticks separately for each buffer
This commit is contained in:
parent
85079c0330
commit
9964c18ced
1 changed files with 5 additions and 4 deletions
|
@ -1,6 +1,6 @@
|
||||||
local codemp = require("libcodemp_nvim")
|
local codemp = require("libcodemp_nvim")
|
||||||
|
|
||||||
local codemp_changed_tick = 0 -- TODO this doesn't work when events are coalesced
|
local codemp_changed_tick = {}
|
||||||
|
|
||||||
local function register_controller_handler(target, controller, handler, delay)
|
local function register_controller_handler(target, controller, handler, delay)
|
||||||
local async = vim.loop.new_async(function()
|
local async = vim.loop.new_async(function()
|
||||||
|
@ -227,6 +227,7 @@ vim.api.nvim_create_user_command(
|
||||||
|
|
||||||
buffer_mappings[buffer] = args.args
|
buffer_mappings[buffer] = args.args
|
||||||
buffer_mappings_reverse[args.args] = buffer
|
buffer_mappings_reverse[args.args] = buffer
|
||||||
|
codemp_changed_tick[buffer] = 0
|
||||||
|
|
||||||
-- hook serverbound callbacks
|
-- hook serverbound callbacks
|
||||||
-- TODO breaks when deleting whole lines at buffer end
|
-- TODO breaks when deleting whole lines at buffer end
|
||||||
|
@ -250,7 +251,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[buffer] = vim.api.nvim_buf_get_changedtick(buffer)
|
||||||
buffer_replace_content(buffer, event.first, event.last, event.content)
|
buffer_replace_content(buffer, event.first, event.last, event.content)
|
||||||
end, 500) -- delay by 200 ms as ugly fix
|
end, 500) -- delay by 200 ms as ugly fix
|
||||||
|
|
||||||
|
@ -261,12 +262,12 @@ vim.api.nvim_create_user_command(
|
||||||
|
|
||||||
vim.api.nvim_create_user_command(
|
vim.api.nvim_create_user_command(
|
||||||
"Sync",
|
"Sync",
|
||||||
function (args)
|
function (_)
|
||||||
local buffer = vim.api.nvim_get_current_buf()
|
local buffer = vim.api.nvim_get_current_buf()
|
||||||
local name = buffer_mappings[buffer]
|
local name = buffer_mappings[buffer]
|
||||||
if name ~= nil then
|
if name ~= nil then
|
||||||
local controller = codemp.get_buffer(name)
|
local controller = codemp.get_buffer(name)
|
||||||
codemp_changed_tick = vim.api.nvim_buf_get_changedtick(buffer) + 1
|
codemp_changed_tick[buffer] = vim.api.nvim_buf_get_changedtick(buffer)
|
||||||
buffer_set_content(buffer, controller.content)
|
buffer_set_content(buffer, controller.content)
|
||||||
print(" :: synched buffer " .. name)
|
print(" :: synched buffer " .. name)
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue