diff --git a/crates/loro-ffi/src/container/text.rs b/crates/loro-ffi/src/container/text.rs index 4a1a4f9aa..56508102a 100644 --- a/crates/loro-ffi/src/container/text.rs +++ b/crates/loro-ffi/src/container/text.rs @@ -1,8 +1,9 @@ use std::{fmt::Display, sync::Arc}; -use loro::{cursor::Side, LoroResult, PeerID, TextDelta, UpdateOptions, UpdateTimeoutError}; +use loro::{cursor::Side, LoroResult, PeerID, UpdateOptions, UpdateTimeoutError}; +use loro_internal::handler::TextDelta as InternalTextDelta; -use crate::{ContainerID, LoroValue, LoroValueLike}; +use crate::{ContainerID, LoroValue, LoroValueLike, TextDelta}; use super::Cursor; @@ -107,8 +108,9 @@ impl LoroText { /// Apply a [delta](https://quilljs.com/docs/delta/) to the text container. // TODO: - pub fn apply_delta(&self, delta: &[TextDelta]) -> LoroResult<()> { - self.text.apply_delta(delta) + pub fn apply_delta(&self, delta: Vec) -> LoroResult<()> { + let internal_delta: Vec = delta.into_iter().map(|d| d.into()).collect(); + self.text.apply_delta(&internal_delta) } /// Mark a range of text with a key-value pair. diff --git a/crates/loro-ffi/src/event.rs b/crates/loro-ffi/src/event.rs index bd6285c9f..fe26afebb 100644 --- a/crates/loro-ffi/src/event.rs +++ b/crates/loro-ffi/src/event.rs @@ -83,6 +83,32 @@ pub enum TextDelta { }, } +impl From for loro_internal::handler::TextDelta { + fn from(value: TextDelta) -> Self { + match value { + TextDelta::Retain { retain, attributes } => loro_internal::handler::TextDelta::Retain { + retain: retain as usize, + attributes: attributes.as_ref().map(|a| { + a.iter() + .map(|(k, v)| (k.to_string(), v.clone().into())) + .collect() + }), + }, + TextDelta::Insert { insert, attributes } => loro_internal::handler::TextDelta::Insert { + insert, + attributes: attributes.as_ref().map(|a| { + a.iter() + .map(|(k, v)| (k.to_string(), v.clone().into())) + .collect() + }), + }, + TextDelta::Delete { delete } => loro_internal::handler::TextDelta::Delete { + delete: delete as usize, + }, + } + } +} + pub enum ListDiffItem { /// Insert a new element into the list. Insert {