diff --git a/frontend/rust-lib/flowy-revision/src/conflict_resolve.rs b/frontend/rust-lib/flowy-revision/src/conflict_resolve.rs index 8b36d554cd..afb8379631 100644 --- a/frontend/rust-lib/flowy-revision/src/conflict_resolve.rs +++ b/frontend/rust-lib/flowy-revision/src/conflict_resolve.rs @@ -10,7 +10,7 @@ use flowy_sync::{ }; use lib_infra::future::BoxResultFuture; use lib_ot::core::{Attributes, Delta, PhantomAttributes}; -use lib_ot::rich_text::RichTextAttributes; +use lib_ot::rich_text::TextAttributes; use serde::de::DeserializeOwned; use std::{convert::TryFrom, sync::Arc}; @@ -30,7 +30,7 @@ pub trait ConflictRevisionSink: Send + Sync + 'static { fn ack(&self, rev_id: String, ty: ServerRevisionWSDataType) -> BoxResultFuture<(), FlowyError>; } -pub type RichTextConflictController = ConflictController; +pub type RichTextConflictController = ConflictController; pub type PlainTextConflictController = ConflictController; pub struct ConflictController @@ -175,7 +175,7 @@ where } } -pub type RichTextTransformDeltas = TransformDeltas; +pub type RichTextTransformDeltas = TransformDeltas; pub struct TransformDeltas where diff --git a/frontend/rust-lib/flowy-text-block/src/editor.rs b/frontend/rust-lib/flowy-text-block/src/editor.rs index 2649b2bae1..ccbfe3d694 100644 --- a/frontend/rust-lib/flowy-text-block/src/editor.rs +++ b/frontend/rust-lib/flowy-text-block/src/editor.rs @@ -15,7 +15,7 @@ use flowy_sync::{ }; use lib_ot::{ core::{Interval, Operation}, - rich_text::{RichTextAttribute, RichTextDelta}, + rich_text::{RichTextDelta, TextAttribute}, }; use lib_ws::WSConnectState; use std::sync::Arc; @@ -85,7 +85,7 @@ impl TextBlockEditor { Ok(()) } - pub async fn format(&self, interval: Interval, attribute: RichTextAttribute) -> Result<(), FlowyError> { + pub async fn format(&self, interval: Interval, attribute: TextAttribute) -> Result<(), FlowyError> { let (ret, rx) = oneshot::channel::>(); let msg = EditorCommand::Format { interval, diff --git a/frontend/rust-lib/flowy-text-block/src/queue.rs b/frontend/rust-lib/flowy-text-block/src/queue.rs index e48c39fb97..b9a98f1529 100644 --- a/frontend/rust-lib/flowy-text-block/src/queue.rs +++ b/frontend/rust-lib/flowy-text-block/src/queue.rs @@ -13,7 +13,7 @@ use flowy_sync::{ use futures::stream::StreamExt; use lib_ot::{ core::{Interval, OperationTransform}, - rich_text::{RichTextAttribute, RichTextAttributes, RichTextDelta}, + rich_text::{RichTextDelta, TextAttribute, TextAttributes}, }; use std::sync::Arc; use tokio::sync::{oneshot, RwLock}; @@ -194,7 +194,7 @@ impl EditBlockQueue { pub(crate) struct TextBlockRevisionCompactor(); impl RevisionCompactor for TextBlockRevisionCompactor { fn bytes_from_revisions(&self, revisions: Vec) -> FlowyResult { - let delta = make_delta_from_revisions::(revisions)?; + let delta = make_delta_from_revisions::(revisions)?; Ok(delta.json_bytes()) } } @@ -229,7 +229,7 @@ pub(crate) enum EditorCommand { }, Format { interval: Interval, - attribute: RichTextAttribute, + attribute: TextAttribute, ret: Ret<()>, }, Replace { diff --git a/frontend/rust-lib/flowy-text-block/src/web_socket.rs b/frontend/rust-lib/flowy-text-block/src/web_socket.rs index a44214f4f2..e4919b917a 100644 --- a/frontend/rust-lib/flowy-text-block/src/web_socket.rs +++ b/frontend/rust-lib/flowy-text-block/src/web_socket.rs @@ -10,8 +10,8 @@ use flowy_sync::{ errors::CollaborateResult, }; use lib_infra::future::{BoxResultFuture, FutureResult}; -use lib_ot::rich_text::RichTextAttributes; use lib_ot::rich_text::RichTextDelta; +use lib_ot::rich_text::TextAttributes; use lib_ws::WSConnectState; use std::{sync::Arc, time::Duration}; use tokio::sync::{ @@ -111,7 +111,7 @@ struct TextBlockConflictResolver { edit_cmd_tx: EditorCommandSender, } -impl ConflictResolver for TextBlockConflictResolver { +impl ConflictResolver for TextBlockConflictResolver { fn compose_delta(&self, delta: RichTextDelta) -> BoxResultFuture { let tx = self.edit_cmd_tx.clone(); Box::pin(async move { diff --git a/frontend/rust-lib/flowy-text-block/tests/editor/mod.rs b/frontend/rust-lib/flowy-text-block/tests/editor/mod.rs index bbfd1da6f8..8f2921d203 100644 --- a/frontend/rust-lib/flowy-text-block/tests/editor/mod.rs +++ b/frontend/rust-lib/flowy-text-block/tests/editor/mod.rs @@ -8,7 +8,7 @@ use derive_more::Display; use flowy_sync::client_document::{ClientDocument, InitialDocumentText}; use lib_ot::{ core::*, - rich_text::{RichTextAttribute, RichTextAttributes, RichTextDelta}, + rich_text::{RichTextDelta, TextAttribute, TextAttributes}, }; use rand::{prelude::*, Rng as WrappedRng}; use std::{sync::Once, time::Duration}; @@ -127,11 +127,11 @@ impl TestBuilder { TestOp::InsertBold(delta_i, s, iv) => { let document = &mut self.documents[*delta_i]; document.insert(iv.start, s).unwrap(); - document.format(*iv, RichTextAttribute::Bold(true)).unwrap(); + document.format(*iv, TextAttribute::Bold(true)).unwrap(); } TestOp::Bold(delta_i, iv, enable) => { let document = &mut self.documents[*delta_i]; - let attribute = RichTextAttribute::Bold(*enable); + let attribute = TextAttribute::Bold(*enable); let delta = document.format(*iv, attribute).unwrap(); tracing::trace!("Bold delta: {}", delta.json_str()); self.deltas.insert(*delta_i, Some(delta)); @@ -139,8 +139,8 @@ impl TestBuilder { TestOp::Italic(delta_i, iv, enable) => { let document = &mut self.documents[*delta_i]; let attribute = match *enable { - true => RichTextAttribute::Italic(true), - false => RichTextAttribute::Italic(false), + true => TextAttribute::Italic(true), + false => TextAttribute::Italic(false), }; let delta = document.format(*iv, attribute).unwrap(); tracing::trace!("Italic delta: {}", delta.json_str()); @@ -148,21 +148,21 @@ impl TestBuilder { } TestOp::Header(delta_i, iv, level) => { let document = &mut self.documents[*delta_i]; - let attribute = RichTextAttribute::Header(*level); + let attribute = TextAttribute::Header(*level); let delta = document.format(*iv, attribute).unwrap(); tracing::trace!("Header delta: {}", delta.json_str()); self.deltas.insert(*delta_i, Some(delta)); } TestOp::Link(delta_i, iv, link) => { let document = &mut self.documents[*delta_i]; - let attribute = RichTextAttribute::Link(link.to_owned()); + let attribute = TextAttribute::Link(link.to_owned()); let delta = document.format(*iv, attribute).unwrap(); tracing::trace!("Link delta: {}", delta.json_str()); self.deltas.insert(*delta_i, Some(delta)); } TestOp::Bullet(delta_i, iv, enable) => { let document = &mut self.documents[*delta_i]; - let attribute = RichTextAttribute::Bullet(*enable); + let attribute = TextAttribute::Bullet(*enable); let delta = document.format(*iv, attribute).unwrap(); tracing::debug!("Bullet delta: {}", delta.json_str()); @@ -313,18 +313,18 @@ impl Rng { }; match self.0.gen_range(0.0..1.0) { f if f < 0.2 => { - delta.insert(&self.gen_string(i), RichTextAttributes::default()); + delta.insert(&self.gen_string(i), TextAttributes::default()); } f if f < 0.4 => { delta.delete(i); } _ => { - delta.retain(i, RichTextAttributes::default()); + delta.retain(i, TextAttributes::default()); } } } if self.0.gen_range(0.0..1.0) < 0.3 { - delta.insert(&("1".to_owned() + &self.gen_string(10)), RichTextAttributes::default()); + delta.insert(&("1".to_owned() + &self.gen_string(10)), TextAttributes::default()); } delta } diff --git a/frontend/rust-lib/flowy-text-block/tests/editor/op_test.rs b/frontend/rust-lib/flowy-text-block/tests/editor/op_test.rs index 99d3136e55..fd25a2e8f2 100644 --- a/frontend/rust-lib/flowy-text-block/tests/editor/op_test.rs +++ b/frontend/rust-lib/flowy-text-block/tests/editor/op_test.rs @@ -5,7 +5,7 @@ use lib_ot::rich_text::RichTextDeltaBuilder; use lib_ot::{ core::Interval, core::*, - rich_text::{AttributeBuilder, RichTextAttribute, RichTextAttributes, RichTextDelta}, + rich_text::{AttributeBuilder, RichTextDelta, TextAttribute, TextAttributes}, }; #[test] @@ -207,8 +207,8 @@ fn delta_utf16_code_unit_seek() { fn delta_utf16_code_unit_seek_with_attributes() { let mut delta = RichTextDelta::default(); let attributes = AttributeBuilder::new() - .add_attr(RichTextAttribute::Bold(true)) - .add_attr(RichTextAttribute::Italic(true)) + .add_attr(TextAttribute::Bold(true)) + .add_attr(TextAttribute::Italic(true)) .build(); delta.add(Operation::insert_with_attributes("1234", attributes.clone())); @@ -304,13 +304,13 @@ fn lengths() { let mut delta = RichTextDelta::default(); assert_eq!(delta.utf16_base_len, 0); assert_eq!(delta.utf16_target_len, 0); - delta.retain(5, RichTextAttributes::default()); + delta.retain(5, TextAttributes::default()); assert_eq!(delta.utf16_base_len, 5); assert_eq!(delta.utf16_target_len, 5); - delta.insert("abc", RichTextAttributes::default()); + delta.insert("abc", TextAttributes::default()); assert_eq!(delta.utf16_base_len, 5); assert_eq!(delta.utf16_target_len, 8); - delta.retain(2, RichTextAttributes::default()); + delta.retain(2, TextAttributes::default()); assert_eq!(delta.utf16_base_len, 7); assert_eq!(delta.utf16_target_len, 10); delta.delete(2); @@ -320,10 +320,10 @@ fn lengths() { #[test] fn sequence() { let mut delta = RichTextDelta::default(); - delta.retain(5, RichTextAttributes::default()); - delta.retain(0, RichTextAttributes::default()); - delta.insert("appflowy", RichTextAttributes::default()); - delta.insert("", RichTextAttributes::default()); + delta.retain(5, TextAttributes::default()); + delta.retain(0, TextAttributes::default()); + delta.insert("appflowy", TextAttributes::default()); + delta.insert("", TextAttributes::default()); delta.delete(3); delta.delete(0); assert_eq!(delta.ops.len(), 3); @@ -353,15 +353,15 @@ fn apply_test() { #[test] fn base_len_test() { let mut delta_a = RichTextDelta::default(); - delta_a.insert("a", RichTextAttributes::default()); - delta_a.insert("b", RichTextAttributes::default()); - delta_a.insert("c", RichTextAttributes::default()); + delta_a.insert("a", TextAttributes::default()); + delta_a.insert("b", TextAttributes::default()); + delta_a.insert("c", TextAttributes::default()); let s = "hello world,".to_owned(); delta_a.delete(s.len()); let after_a = delta_a.apply(&s).unwrap(); - delta_a.insert("d", RichTextAttributes::default()); + delta_a.insert("d", TextAttributes::default()); assert_eq!("abc", &after_a); } @@ -392,8 +392,8 @@ fn invert_test() { #[test] fn empty_ops() { let mut delta = RichTextDelta::default(); - delta.retain(0, RichTextAttributes::default()); - delta.insert("", RichTextAttributes::default()); + delta.retain(0, TextAttributes::default()); + delta.insert("", TextAttributes::default()); delta.delete(0); assert_eq!(delta.ops.len(), 0); } @@ -401,33 +401,33 @@ fn empty_ops() { fn eq() { let mut delta_a = RichTextDelta::default(); delta_a.delete(1); - delta_a.insert("lo", RichTextAttributes::default()); - delta_a.retain(2, RichTextAttributes::default()); - delta_a.retain(3, RichTextAttributes::default()); + delta_a.insert("lo", TextAttributes::default()); + delta_a.retain(2, TextAttributes::default()); + delta_a.retain(3, TextAttributes::default()); let mut delta_b = RichTextDelta::default(); delta_b.delete(1); - delta_b.insert("l", RichTextAttributes::default()); - delta_b.insert("o", RichTextAttributes::default()); - delta_b.retain(5, RichTextAttributes::default()); + delta_b.insert("l", TextAttributes::default()); + delta_b.insert("o", TextAttributes::default()); + delta_b.retain(5, TextAttributes::default()); assert_eq!(delta_a, delta_b); delta_a.delete(1); - delta_b.retain(1, RichTextAttributes::default()); + delta_b.retain(1, TextAttributes::default()); assert_ne!(delta_a, delta_b); } #[test] fn ops_merging() { let mut delta = RichTextDelta::default(); assert_eq!(delta.ops.len(), 0); - delta.retain(2, RichTextAttributes::default()); + delta.retain(2, TextAttributes::default()); assert_eq!(delta.ops.len(), 1); assert_eq!(delta.ops.last(), Some(&Operation::retain(2))); - delta.retain(3, RichTextAttributes::default()); + delta.retain(3, TextAttributes::default()); assert_eq!(delta.ops.len(), 1); assert_eq!(delta.ops.last(), Some(&Operation::retain(5))); - delta.insert("abc", RichTextAttributes::default()); + delta.insert("abc", TextAttributes::default()); assert_eq!(delta.ops.len(), 2); assert_eq!(delta.ops.last(), Some(&Operation::insert("abc"))); - delta.insert("xyz", RichTextAttributes::default()); + delta.insert("xyz", TextAttributes::default()); assert_eq!(delta.ops.len(), 2); assert_eq!(delta.ops.last(), Some(&Operation::insert("abcxyz"))); delta.delete(1); @@ -442,11 +442,11 @@ fn ops_merging() { fn is_noop() { let mut delta = RichTextDelta::default(); assert!(delta.is_noop()); - delta.retain(5, RichTextAttributes::default()); + delta.retain(5, TextAttributes::default()); assert!(delta.is_noop()); - delta.retain(3, RichTextAttributes::default()); + delta.retain(3, TextAttributes::default()); assert!(delta.is_noop()); - delta.insert("lorem", RichTextAttributes::default()); + delta.insert("lorem", TextAttributes::default()); assert!(!delta.is_noop()); } #[test] @@ -492,14 +492,14 @@ fn transform_with_two_delta() { let mut a_s = String::new(); a.insert( "123", - AttributeBuilder::new().add_attr(RichTextAttribute::Bold(true)).build(), + AttributeBuilder::new().add_attr(TextAttribute::Bold(true)).build(), ); a_s = a.apply(&a_s).unwrap(); assert_eq!(&a_s, "123"); let mut b = RichTextDelta::default(); let mut b_s = String::new(); - b.insert("456", RichTextAttributes::default()); + b.insert("456", TextAttributes::default()); b_s = b.apply(&b_s).unwrap(); assert_eq!(&b_s, "456"); diff --git a/frontend/rust-lib/flowy-text-block/tests/editor/serde_test.rs b/frontend/rust-lib/flowy-text-block/tests/editor/serde_test.rs index ac4a77412c..2d2e6bc143 100644 --- a/frontend/rust-lib/flowy-text-block/tests/editor/serde_test.rs +++ b/frontend/rust-lib/flowy-text-block/tests/editor/serde_test.rs @@ -2,14 +2,14 @@ use flowy_sync::client_document::{ClientDocument, PlainDoc}; use lib_ot::rich_text::RichTextOperation; use lib_ot::{ core::*, - rich_text::{AttributeBuilder, RichTextAttribute, RichTextAttributeValue, RichTextDelta}, + rich_text::{AttributeBuilder, RichTextDelta, TextAttribute, TextAttributeValue}, }; #[test] fn operation_insert_serialize_test() { let attributes = AttributeBuilder::new() - .add_attr(RichTextAttribute::Bold(true)) - .add_attr(RichTextAttribute::Italic(true)) + .add_attr(TextAttribute::Bold(true)) + .add_attr(TextAttribute::Italic(true)) .build(); let operation = Operation::insert_with_attributes("123", attributes); let json = serde_json::to_string(&operation).unwrap(); @@ -39,8 +39,8 @@ fn operation_delete_serialize_test() { #[test] fn attributes_serialize_test() { let attributes = AttributeBuilder::new() - .add_attr(RichTextAttribute::Bold(true)) - .add_attr(RichTextAttribute::Italic(true)) + .add_attr(TextAttribute::Bold(true)) + .add_attr(TextAttribute::Italic(true)) .build(); let retain = Operation::insert_with_attributes("123", attributes); @@ -53,8 +53,8 @@ fn delta_serialize_multi_attribute_test() { let mut delta = Delta::default(); let attributes = AttributeBuilder::new() - .add_attr(RichTextAttribute::Bold(true)) - .add_attr(RichTextAttribute::Italic(true)) + .add_attr(TextAttribute::Bold(true)) + .add_attr(TextAttribute::Italic(true)) .build(); let retain = Operation::insert_with_attributes("123", attributes); @@ -88,8 +88,8 @@ fn delta_deserialize_null_test() { ]"#; let delta1 = RichTextDelta::from_json(json).unwrap(); - let mut attribute = RichTextAttribute::Bold(true); - attribute.value = RichTextAttributeValue(None); + let mut attribute = TextAttribute::Bold(true); + attribute.value = TextAttributeValue(None); let delta2 = DeltaBuilder::new().retain_with_attributes(7, attribute.into()).build(); assert_eq!(delta2.json_str(), r#"[{"retain":7,"attributes":{"bold":""}}]"#); @@ -98,8 +98,8 @@ fn delta_deserialize_null_test() { #[test] fn delta_serde_null_test() { - let mut attribute = RichTextAttribute::Bold(true); - attribute.value = RichTextAttributeValue(None); + let mut attribute = TextAttribute::Bold(true); + attribute.value = TextAttributeValue(None); assert_eq!(attribute.to_json(), r#"{"bold":""}"#); } diff --git a/shared-lib/flowy-sync/src/client_document/document_pad.rs b/shared-lib/flowy-sync/src/client_document/document_pad.rs index 9a1037d0c8..28915e259d 100644 --- a/shared-lib/flowy-sync/src/client_document/document_pad.rs +++ b/shared-lib/flowy-sync/src/client_document/document_pad.rs @@ -9,7 +9,7 @@ use crate::{ use bytes::Bytes; use lib_ot::{ core::*, - rich_text::{RichTextAttribute, RichTextDelta}, + rich_text::{RichTextDelta, TextAttribute}, }; use tokio::sync::mpsc; @@ -141,11 +141,7 @@ impl ClientDocument { Ok(delete) } - pub fn format( - &mut self, - interval: Interval, - attribute: RichTextAttribute, - ) -> Result { + pub fn format(&mut self, interval: Interval, attribute: TextAttribute) -> Result { let _ = validate_interval(&self.delta, &interval)?; tracing::trace!("format {} with {}", interval, attribute); let format_delta = self.view.format(&self.delta, attribute, interval).unwrap(); diff --git a/shared-lib/flowy-sync/src/client_document/extensions/format/resolve_block_format.rs b/shared-lib/flowy-sync/src/client_document/extensions/format/resolve_block_format.rs index 4a4c00a19d..3437080f37 100644 --- a/shared-lib/flowy-sync/src/client_document/extensions/format/resolve_block_format.rs +++ b/shared-lib/flowy-sync/src/client_document/extensions/format/resolve_block_format.rs @@ -1,6 +1,6 @@ use lib_ot::{ core::{DeltaBuilder, DeltaIterator, Interval}, - rich_text::{plain_attributes, AttributeScope, RichTextAttribute, RichTextDelta}, + rich_text::{plain_attributes, AttributeScope, RichTextDelta, TextAttribute}, }; use crate::{ @@ -14,7 +14,7 @@ impl FormatExt for ResolveBlockFormat { "ResolveBlockFormat" } - fn apply(&self, delta: &RichTextDelta, interval: Interval, attribute: &RichTextAttribute) -> Option { + fn apply(&self, delta: &RichTextDelta, interval: Interval, attribute: &TextAttribute) -> Option { if attribute.scope != AttributeScope::Block { return None; } diff --git a/shared-lib/flowy-sync/src/client_document/extensions/format/resolve_inline_format.rs b/shared-lib/flowy-sync/src/client_document/extensions/format/resolve_inline_format.rs index 567d06d6f2..8b654b0787 100644 --- a/shared-lib/flowy-sync/src/client_document/extensions/format/resolve_inline_format.rs +++ b/shared-lib/flowy-sync/src/client_document/extensions/format/resolve_inline_format.rs @@ -1,6 +1,6 @@ use lib_ot::{ core::{DeltaBuilder, DeltaIterator, Interval}, - rich_text::{AttributeScope, RichTextAttribute, RichTextDelta}, + rich_text::{AttributeScope, RichTextDelta, TextAttribute}, }; use crate::{ @@ -14,7 +14,7 @@ impl FormatExt for ResolveInlineFormat { "ResolveInlineFormat" } - fn apply(&self, delta: &RichTextDelta, interval: Interval, attribute: &RichTextAttribute) -> Option { + fn apply(&self, delta: &RichTextDelta, interval: Interval, attribute: &TextAttribute) -> Option { if attribute.scope != AttributeScope::Inline { return None; } diff --git a/shared-lib/flowy-sync/src/client_document/extensions/helper.rs b/shared-lib/flowy-sync/src/client_document/extensions/helper.rs index a4745bf7ca..6c6a0e2d25 100644 --- a/shared-lib/flowy-sync/src/client_document/extensions/helper.rs +++ b/shared-lib/flowy-sync/src/client_document/extensions/helper.rs @@ -1,11 +1,7 @@ use crate::util::find_newline; -use lib_ot::rich_text::{plain_attributes, AttributeScope, RichTextAttribute, RichTextDelta, RichTextOperation}; +use lib_ot::rich_text::{plain_attributes, AttributeScope, RichTextDelta, RichTextOperation, TextAttribute}; -pub(crate) fn line_break( - op: &RichTextOperation, - attribute: &RichTextAttribute, - scope: AttributeScope, -) -> RichTextDelta { +pub(crate) fn line_break(op: &RichTextOperation, attribute: &TextAttribute, scope: AttributeScope) -> RichTextDelta { let mut new_delta = RichTextDelta::new(); let mut start = 0; let end = op.len(); diff --git a/shared-lib/flowy-sync/src/client_document/extensions/insert/auto_exit_block.rs b/shared-lib/flowy-sync/src/client_document/extensions/insert/auto_exit_block.rs index 253833d255..d7a0b7dea5 100644 --- a/shared-lib/flowy-sync/src/client_document/extensions/insert/auto_exit_block.rs +++ b/shared-lib/flowy-sync/src/client_document/extensions/insert/auto_exit_block.rs @@ -1,6 +1,6 @@ use crate::{client_document::InsertExt, util::is_newline}; use lib_ot::core::{is_empty_line_at_index, DeltaBuilder, DeltaIterator}; -use lib_ot::rich_text::{attributes_except_header, RichTextAttributeKey, RichTextDelta}; +use lib_ot::rich_text::{attributes_except_header, RichTextDelta, TextAttributeKey}; pub struct AutoExitBlock {} @@ -42,7 +42,7 @@ impl InsertExt for AutoExitBlock { } } - attributes.mark_all_as_removed_except(Some(RichTextAttributeKey::Header)); + attributes.mark_all_as_removed_except(Some(TextAttributeKey::Header)); Some( DeltaBuilder::new() diff --git a/shared-lib/flowy-sync/src/client_document/extensions/insert/auto_format.rs b/shared-lib/flowy-sync/src/client_document/extensions/insert/auto_format.rs index 4c7cd642c2..07e9d3d116 100644 --- a/shared-lib/flowy-sync/src/client_document/extensions/insert/auto_format.rs +++ b/shared-lib/flowy-sync/src/client_document/extensions/insert/auto_format.rs @@ -1,7 +1,7 @@ use crate::{client_document::InsertExt, util::is_whitespace}; use lib_ot::{ core::{count_utf16_code_units, DeltaBuilder, DeltaIterator}, - rich_text::{plain_attributes, RichTextAttribute, RichTextAttributes, RichTextDelta}, + rich_text::{plain_attributes, RichTextDelta, TextAttribute, TextAttributes}, }; use std::cmp::min; use url::Url; @@ -60,9 +60,9 @@ pub enum AutoFormatter { } impl AutoFormatter { - pub fn to_attributes(&self) -> RichTextAttributes { + pub fn to_attributes(&self) -> TextAttributes { match self { - AutoFormatter::Url(url) => RichTextAttribute::Link(url.as_str()).into(), + AutoFormatter::Url(url) => TextAttribute::Link(url.as_str()).into(), } } diff --git a/shared-lib/flowy-sync/src/client_document/extensions/insert/default_insert.rs b/shared-lib/flowy-sync/src/client_document/extensions/insert/default_insert.rs index c165985493..3f29404136 100644 --- a/shared-lib/flowy-sync/src/client_document/extensions/insert/default_insert.rs +++ b/shared-lib/flowy-sync/src/client_document/extensions/insert/default_insert.rs @@ -1,7 +1,7 @@ use crate::client_document::InsertExt; use lib_ot::{ core::{Attributes, DeltaBuilder, DeltaIterator, NEW_LINE}, - rich_text::{RichTextAttributeKey, RichTextAttributes, RichTextDelta}, + rich_text::{RichTextDelta, TextAttributeKey, TextAttributes}, }; pub struct DefaultInsertAttribute {} @@ -12,7 +12,7 @@ impl InsertExt for DefaultInsertAttribute { fn apply(&self, delta: &RichTextDelta, replace_len: usize, text: &str, index: usize) -> Option { let iter = DeltaIterator::new(delta); - let mut attributes = RichTextAttributes::new(); + let mut attributes = TextAttributes::new(); // Enable each line split by "\n" remains the block attributes. for example: // insert "\n" to "123456" at index 3 @@ -23,7 +23,7 @@ impl InsertExt for DefaultInsertAttribute { match iter.last() { None => {} Some(op) => { - if op.get_attributes().contains_key(&RichTextAttributeKey::Header) { + if op.get_attributes().contains_key(&TextAttributeKey::Header) { attributes.extend_other(op.get_attributes()); } } diff --git a/shared-lib/flowy-sync/src/client_document/extensions/insert/preserve_block_format.rs b/shared-lib/flowy-sync/src/client_document/extensions/insert/preserve_block_format.rs index 03c9723d7b..21c781524f 100644 --- a/shared-lib/flowy-sync/src/client_document/extensions/insert/preserve_block_format.rs +++ b/shared-lib/flowy-sync/src/client_document/extensions/insert/preserve_block_format.rs @@ -2,8 +2,7 @@ use crate::{client_document::InsertExt, util::is_newline}; use lib_ot::{ core::{DeltaBuilder, DeltaIterator, NEW_LINE}, rich_text::{ - attributes_except_header, plain_attributes, RichTextAttribute, RichTextAttributeKey, RichTextAttributes, - RichTextDelta, + attributes_except_header, plain_attributes, RichTextDelta, TextAttribute, TextAttributeKey, TextAttributes, }, }; @@ -28,9 +27,9 @@ impl InsertExt for PreserveBlockFormatOnInsert { return None; } - let mut reset_attribute = RichTextAttributes::new(); - if newline_attributes.contains_key(&RichTextAttributeKey::Header) { - reset_attribute.add(RichTextAttribute::Header(1)); + let mut reset_attribute = TextAttributes::new(); + if newline_attributes.contains_key(&TextAttributeKey::Header) { + reset_attribute.add(TextAttribute::Header(1)); } let lines: Vec<_> = text.split(NEW_LINE).collect(); diff --git a/shared-lib/flowy-sync/src/client_document/extensions/insert/preserve_inline_format.rs b/shared-lib/flowy-sync/src/client_document/extensions/insert/preserve_inline_format.rs index b0de6451aa..be65a1432d 100644 --- a/shared-lib/flowy-sync/src/client_document/extensions/insert/preserve_inline_format.rs +++ b/shared-lib/flowy-sync/src/client_document/extensions/insert/preserve_inline_format.rs @@ -4,7 +4,7 @@ use crate::{ }; use lib_ot::{ core::{DeltaBuilder, DeltaIterator, OpNewline, NEW_LINE}, - rich_text::{plain_attributes, RichTextAttributeKey, RichTextDelta}, + rich_text::{plain_attributes, RichTextDelta, TextAttributeKey}, }; pub struct PreserveInlineFormat {} @@ -25,7 +25,7 @@ impl InsertExt for PreserveInlineFormat { } let mut attributes = prev.get_attributes(); - if attributes.is_empty() || !attributes.contains_key(&RichTextAttributeKey::Link) { + if attributes.is_empty() || !attributes.contains_key(&TextAttributeKey::Link) { return Some( DeltaBuilder::new() .retain(index + replace_len) diff --git a/shared-lib/flowy-sync/src/client_document/extensions/insert/reset_format_on_new_line.rs b/shared-lib/flowy-sync/src/client_document/extensions/insert/reset_format_on_new_line.rs index 8671049ee7..3324df3398 100644 --- a/shared-lib/flowy-sync/src/client_document/extensions/insert/reset_format_on_new_line.rs +++ b/shared-lib/flowy-sync/src/client_document/extensions/insert/reset_format_on_new_line.rs @@ -1,7 +1,7 @@ use crate::{client_document::InsertExt, util::is_newline}; use lib_ot::{ core::{DeltaBuilder, DeltaIterator, Utf16CodeUnitMetric, NEW_LINE}, - rich_text::{RichTextAttributeKey, RichTextAttributes, RichTextDelta}, + rich_text::{RichTextDelta, TextAttributeKey, TextAttributes}, }; pub struct ResetLineFormatOnNewLine {} @@ -22,9 +22,9 @@ impl InsertExt for ResetLineFormatOnNewLine { return None; } - let mut reset_attribute = RichTextAttributes::new(); - if next_op.get_attributes().contains_key(&RichTextAttributeKey::Header) { - reset_attribute.delete(&RichTextAttributeKey::Header); + let mut reset_attribute = TextAttributes::new(); + if next_op.get_attributes().contains_key(&TextAttributeKey::Header) { + reset_attribute.delete(&TextAttributeKey::Header); } let len = index + replace_len; diff --git a/shared-lib/flowy-sync/src/client_document/extensions/mod.rs b/shared-lib/flowy-sync/src/client_document/extensions/mod.rs index d24e78fab1..ffbb6c0a9e 100644 --- a/shared-lib/flowy-sync/src/client_document/extensions/mod.rs +++ b/shared-lib/flowy-sync/src/client_document/extensions/mod.rs @@ -3,7 +3,7 @@ pub use format::*; pub use insert::*; use lib_ot::{ core::Interval, - rich_text::{RichTextAttribute, RichTextDelta}, + rich_text::{RichTextDelta, TextAttribute}, }; mod delete; @@ -22,7 +22,7 @@ pub trait InsertExt { pub trait FormatExt { fn ext_name(&self) -> &str; - fn apply(&self, delta: &RichTextDelta, interval: Interval, attribute: &RichTextAttribute) -> Option; + fn apply(&self, delta: &RichTextDelta, interval: Interval, attribute: &TextAttribute) -> Option; } pub trait DeleteExt { diff --git a/shared-lib/flowy-sync/src/client_document/view.rs b/shared-lib/flowy-sync/src/client_document/view.rs index 3aefe8debd..90b33b0312 100644 --- a/shared-lib/flowy-sync/src/client_document/view.rs +++ b/shared-lib/flowy-sync/src/client_document/view.rs @@ -2,7 +2,7 @@ use crate::client_document::*; use lib_ot::{ core::{trim, Interval}, errors::{ErrorBuilder, OTError, OTErrorCode}, - rich_text::{RichTextAttribute, RichTextDelta}, + rich_text::{RichTextDelta, TextAttribute}, }; pub const RECORD_THRESHOLD: usize = 400; // in milliseconds @@ -64,7 +64,7 @@ impl ViewExtensions { pub(crate) fn format( &self, delta: &RichTextDelta, - attribute: RichTextAttribute, + attribute: TextAttribute, interval: Interval, ) -> Result { let mut new_delta = None; diff --git a/shared-lib/flowy-sync/src/server_document/document_manager.rs b/shared-lib/flowy-sync/src/server_document/document_manager.rs index 59d3dd3c97..a7188799f9 100644 --- a/shared-lib/flowy-sync/src/server_document/document_manager.rs +++ b/shared-lib/flowy-sync/src/server_document/document_manager.rs @@ -11,7 +11,7 @@ use async_stream::stream; use dashmap::DashMap; use futures::stream::StreamExt; use lib_infra::future::BoxResultFuture; -use lib_ot::rich_text::{RichTextAttributes, RichTextDelta}; +use lib_ot::rich_text::{RichTextDelta, TextAttributes}; use std::{collections::HashMap, fmt::Debug, sync::Arc}; use tokio::{ sync::{mpsc, oneshot, RwLock}, @@ -198,7 +198,7 @@ impl std::ops::Drop for ServerDocumentManager { } } -type DocumentRevisionSynchronizer = RevisionSynchronizer; +type DocumentRevisionSynchronizer = RevisionSynchronizer; struct OpenDocumentHandler { doc_id: String, diff --git a/shared-lib/flowy-sync/src/server_document/document_pad.rs b/shared-lib/flowy-sync/src/server_document/document_pad.rs index 28623a0169..f444816cd6 100644 --- a/shared-lib/flowy-sync/src/server_document/document_pad.rs +++ b/shared-lib/flowy-sync/src/server_document/document_pad.rs @@ -1,7 +1,7 @@ use crate::{client_document::InitialDocumentText, errors::CollaborateError, synchronizer::RevisionSyncObject}; use lib_ot::{ core::*, - rich_text::{RichTextAttributes, RichTextDelta}, + rich_text::{RichTextDelta, TextAttributes}, }; pub struct ServerDocument { @@ -21,7 +21,7 @@ impl ServerDocument { } } -impl RevisionSyncObject for ServerDocument { +impl RevisionSyncObject for ServerDocument { fn id(&self) -> &str { &self.doc_id } @@ -42,7 +42,7 @@ impl RevisionSyncObject for ServerDocument { self.delta.json_str() } - fn set_delta(&mut self, new_delta: Delta) { + fn set_delta(&mut self, new_delta: Delta) { self.delta = new_delta; } } diff --git a/shared-lib/lib-ot/src/core/operation/operation.rs b/shared-lib/lib-ot/src/core/operation/operation.rs index 4bacd1ea7d..48899ef8ce 100644 --- a/shared-lib/lib-ot/src/core/operation/operation.rs +++ b/shared-lib/lib-ot/src/core/operation/operation.rs @@ -64,7 +64,7 @@ pub trait OperationTransform { fn invert(&self, other: &Self) -> Self; } -/// Each operation can carry attributes. For example, the [RichTextAttributes] has a list of key/value attributes. +/// Each operation can carry attributes. For example, the [TextAttributes] has a list of key/value attributes. /// Such as { bold: true, italic: true }. /// ///Because [Operation] is generic over the T, so you must specify the T. For example, the [TextDelta] uses