config folder collaboration

This commit is contained in:
appflowy
2022-01-15 23:58:36 +08:00
parent 02201c238c
commit 6bca483c28
31 changed files with 346 additions and 385 deletions

View File

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

View File

@ -13,7 +13,7 @@ use std::{
str::FromStr,
};
// TODO: optimize the memory usage with Arc_mut or Cow
// TODO: optimize the memory usage with Arc::make_mut or Cow
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Delta<T: Attributes> {
pub ops: Vec<Operation<T>>,

View File

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

View File

@ -1,12 +1,13 @@
use crate::{
core::{FlowyStr, Interval, OpBuilder, OperationTransformable},
errors::OTError,
rich_text::{RichTextAttribute, RichTextAttributes},
};
use serde::__private::Formatter;
use std::{
cmp::min,
fmt,
fmt::Debug,
fmt::{Debug, Display},
ops::{Deref, DerefMut},
};
@ -19,13 +20,6 @@ pub trait Attributes: fmt::Display + Eq + PartialEq + Default + Clone + Debug +
fn extend_other(&mut self, other: Self);
}
pub type RichTextOperation = Operation<RichTextAttributes>;
impl RichTextOperation {
pub fn contain_attribute(&self, attribute: &RichTextAttribute) -> bool {
self.get_attributes().contains_key(&attribute.key)
}
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum Operation<T: Attributes> {
Delete(usize),
@ -328,3 +322,25 @@ where
}
}
}
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct PlainTextAttributes();
impl fmt::Display for PlainTextAttributes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("PlainTextAttributes") }
}
impl Attributes for PlainTextAttributes {
fn is_empty(&self) -> bool { true }
fn remove_empty(&mut self) {}
fn extend_other(&mut self, _other: Self) {}
}
impl OperationTransformable for PlainTextAttributes {
fn compose(&self, _other: &Self) -> Result<Self, OTError> { Ok(self.clone()) }
fn transform(&self, other: &Self) -> Result<(Self, Self), OTError> { Ok((self.clone(), other.clone())) }
fn invert(&self, _other: &Self) -> Self { self.clone() }
}

View File

@ -1,7 +1,7 @@
#![allow(non_snake_case)]
use crate::{
block_attribute,
core::{Attributes, OperationTransformable, RichTextOperation},
core::{Attributes, Operation, OperationTransformable},
errors::OTError,
ignore_attribute,
inline_attribute,
@ -16,6 +16,13 @@ use std::{
};
use strum_macros::Display;
pub type RichTextOperation = Operation<RichTextAttributes>;
impl RichTextOperation {
pub fn contain_attribute(&self, attribute: &RichTextAttribute) -> bool {
self.get_attributes().contains_key(&attribute.key)
}
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct RichTextAttributes {
pub(crate) inner: HashMap<RichTextAttributeKey, RichTextAttributeValue>,