From c58d1db58bc5f43a738fde837f18c61bb66f4950 Mon Sep 17 00:00:00 2001 From: cschen Date: Wed, 14 Aug 2024 17:16:05 +0200 Subject: [PATCH] fix: proper translation from dt::Operation to Textchange Co-authored-by: alemi --- src/buffer/worker.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/buffer/worker.rs b/src/buffer/worker.rs index 3f7dfeb..ff3405d 100644 --- a/src/buffer/worker.rs +++ b/src/buffer/worker.rs @@ -148,11 +148,27 @@ impl ControllerWorker for BufferWorker { Some(crate::hash(branch.content().to_string())) } else { None }; - let tc = crate::api::change::TextChange { - start: dtop.start() as u32, - end: dtop.end() as u32, - content: dtop.content_as_str().unwrap_or_default().to_string(), - hash + let tc = match dtop.kind { + diamond_types::list::operation::OpKind::Ins => { + if dtop.end() - dtop.start() != dtop.content_as_str().unwrap_or_default().len() { + tracing::error!("[?!?!] Insert span differs from effective content len (TODO remove this error after a bit)"); + } + crate::api::change::TextChange { + start: dtop.start() as u32, + end: dtop.start() as u32, + content: dtop.content_as_str().unwrap_or_default().to_string(), + hash + } + }, + + diamond_types::list::operation::OpKind::Del => { + crate::api::change::TextChange { + start: dtop.start() as u32, + end: dtop.end() as u32, + content: dtop.content_as_str().unwrap_or_default().to_string(), + hash + } + } }; tx.send((new_local_v, tc)).unwrap_or_warn("could not update ops channel -- is controller dead?"); }