mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
refactor: add plugins
This commit is contained in:
@ -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>,
|
||||
|
@ -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)]
|
||||
|
@ -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>,
|
||||
|
@ -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())
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user