refactor: add plugins

This commit is contained in:
appflowy
2022-02-28 22:38:53 +08:00
parent 74831964a6
commit 8747457836
57 changed files with 975 additions and 647 deletions

View File

@ -1,6 +1,6 @@
use crate::core::{trim, Attributes, Delta, PlainAttributes};
use crate::core::{trim, Attributes, Delta, PlainTextAttributes};
pub type PlainDeltaBuilder = DeltaBuilder<PlainAttributes>;
pub type PlainTextDeltaBuilder = DeltaBuilder<PlainTextAttributes>;
pub struct DeltaBuilder<T: Attributes> {
delta: Delta<T>,

View File

@ -13,7 +13,7 @@ use std::{
str::FromStr,
};
pub type PlainDelta = Delta<PlainAttributes>;
pub type PlainTextDelta = Delta<PlainTextAttributes>;
// TODO: optimize the memory usage with Arc::make_mut or Cow
#[derive(Clone, Debug, PartialEq, Eq)]

View File

@ -1,10 +1,10 @@
use crate::{
core::{Attributes, Operation, PlainAttributes},
core::{Attributes, Operation, PlainTextAttributes},
rich_text::RichTextAttributes,
};
pub type RichTextOpBuilder = OpBuilder<RichTextAttributes>;
pub type PlainTextOpBuilder = OpBuilder<PlainAttributes>;
pub type PlainTextOpBuilder = OpBuilder<PlainTextAttributes>;
pub struct OpBuilder<T: Attributes> {
ty: Operation<T>,

View File

@ -339,14 +339,14 @@ where
}
#[derive(Debug, Clone, Eq, PartialEq, Default, Serialize, Deserialize)]
pub struct PlainAttributes();
impl fmt::Display for PlainAttributes {
pub struct PlainTextAttributes();
impl fmt::Display for PlainTextAttributes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("PlainAttributes")
}
}
impl Attributes for PlainAttributes {
impl Attributes for PlainTextAttributes {
fn is_empty(&self) -> bool {
true
}
@ -356,7 +356,7 @@ impl Attributes for PlainAttributes {
fn extend_other(&mut self, _other: Self) {}
}
impl OperationTransformable for PlainAttributes {
impl OperationTransformable for PlainTextAttributes {
fn compose(&self, _other: &Self) -> Result<Self, OTError> {
Ok(self.clone())
}

View File

@ -40,6 +40,7 @@ impl fmt::Display for RichTextAttributes {
}
}
#[inline(always)]
pub fn plain_attributes() -> RichTextAttributes {
RichTextAttributes::default()
}
@ -58,7 +59,7 @@ impl RichTextAttributes {
self.inner.insert(key, value);
}
pub fn add_kv(&mut self, key: RichTextAttributeKey, value: RichTextAttributeValue) {
pub fn insert(&mut self, key: RichTextAttributeKey, value: RichTextAttributeValue) {
self.inner.insert(key, value);
}

View File

@ -101,7 +101,7 @@ impl<'de> Deserialize<'de> for RichTextAttributes {
let mut attributes = RichTextAttributes::new();
while let Some(key) = map.next_key::<RichTextAttributeKey>()? {
let value = map.next_value::<RichTextAttributeValue>()?;
attributes.add_kv(key, value);
attributes.insert(key, value);
}
Ok(attributes)