mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
solver conflicts
This commit is contained in:
@ -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>,
|
||||
|
@ -13,7 +13,9 @@ use std::{
|
||||
str::FromStr,
|
||||
};
|
||||
|
||||
// TODO: optimize the memory usage with Arc_mut or Cow
|
||||
pub type PlainDelta = Delta<PlainTextAttributes>;
|
||||
|
||||
// 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>>,
|
||||
@ -454,8 +456,8 @@ fn invert_from_other<T: Attributes>(
|
||||
tracing::trace!("invert op: {} [{}:{}]", operation, start, end);
|
||||
let other_ops = DeltaIter::from_interval(other, Interval::new(start, end)).ops();
|
||||
other_ops.into_iter().for_each(|other_op| match operation {
|
||||
Operation::Delete(n) => {
|
||||
tracing::trace!("invert delete: {} by add {}", n, other_op);
|
||||
Operation::Delete(_n) => {
|
||||
// tracing::trace!("invert delete: {} by add {}", n, other_op);
|
||||
base.add(other_op);
|
||||
}
|
||||
Operation::Retain(_retain) => {
|
||||
|
@ -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>,
|
||||
|
@ -1,8 +1,8 @@
|
||||
use crate::{
|
||||
core::{FlowyStr, Interval, OpBuilder, OperationTransformable},
|
||||
rich_text::{RichTextAttribute, RichTextAttributes},
|
||||
errors::OTError,
|
||||
};
|
||||
use serde::__private::Formatter;
|
||||
use serde::{Deserialize, Serialize, __private::Formatter};
|
||||
use std::{
|
||||
cmp::min,
|
||||
fmt,
|
||||
@ -19,13 +19,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),
|
||||
@ -209,12 +202,12 @@ where
|
||||
T: Attributes,
|
||||
{
|
||||
pub fn merge_or_new(&mut self, n: usize, attributes: T) -> Option<Operation<T>> {
|
||||
tracing::trace!(
|
||||
"merge_retain_or_new_op: len: {:?}, l: {} - r: {}",
|
||||
n,
|
||||
self.attributes,
|
||||
attributes
|
||||
);
|
||||
// tracing::trace!(
|
||||
// "merge_retain_or_new_op: len: {:?}, l: {} - r: {}",
|
||||
// n,
|
||||
// self.attributes,
|
||||
// attributes
|
||||
// );
|
||||
if self.attributes == attributes {
|
||||
self.n += n;
|
||||
None
|
||||
@ -344,3 +337,25 @@ where
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, Default, Serialize, Deserialize)]
|
||||
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() }
|
||||
}
|
||||
|
@ -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, list_attribute,
|
||||
};
|
||||
@ -14,6 +14,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>,
|
||||
|
Reference in New Issue
Block a user