mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-11-15 18:07:55 +00:00
feat: add operations of the document
This commit is contained in:
parent
7d404ff0da
commit
2466b3eebc
@ -1,5 +1,6 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct NodeAttributes(HashMap<String, Option<String>>);
|
pub struct NodeAttributes(HashMap<String, Option<String>>);
|
||||||
|
|
||||||
impl NodeAttributes {
|
impl NodeAttributes {
|
||||||
|
|||||||
57
shared-lib/lib-ot/src/core/document/document_operation.rs
Normal file
57
shared-lib/lib-ot/src/core/document/document_operation.rs
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
use crate::core::document::position::Position;
|
||||||
|
use crate::core::{NodeAttributes, TextDelta};
|
||||||
|
use indextree::NodeId;
|
||||||
|
|
||||||
|
pub enum DocumentOperation {
|
||||||
|
Insert(InsertOperation),
|
||||||
|
Update(UpdateOperation),
|
||||||
|
Delete(DeleteOperation),
|
||||||
|
TextEdit(TextEditOperation),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DocumentOperation {
|
||||||
|
pub fn invert(&self) -> DocumentOperation {
|
||||||
|
match self {
|
||||||
|
DocumentOperation::Insert(insert_operation) => DocumentOperation::Delete(DeleteOperation {
|
||||||
|
path: insert_operation.path.clone(),
|
||||||
|
nodes: insert_operation.nodes.clone(),
|
||||||
|
}),
|
||||||
|
DocumentOperation::Update(update_operation) => DocumentOperation::Update(UpdateOperation {
|
||||||
|
path: update_operation.path.clone(),
|
||||||
|
attributes: update_operation.old_attributes.clone(),
|
||||||
|
old_attributes: update_operation.attributes.clone(),
|
||||||
|
}),
|
||||||
|
DocumentOperation::Delete(delete_operation) => DocumentOperation::Insert(InsertOperation {
|
||||||
|
path: delete_operation.path.clone(),
|
||||||
|
nodes: delete_operation.nodes.clone(),
|
||||||
|
}),
|
||||||
|
DocumentOperation::TextEdit(text_edit_operation) => DocumentOperation::TextEdit(TextEditOperation {
|
||||||
|
path: text_edit_operation.path.clone(),
|
||||||
|
delta: text_edit_operation.inverted.clone(),
|
||||||
|
inverted: text_edit_operation.delta.clone(),
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct InsertOperation {
|
||||||
|
path: Position,
|
||||||
|
nodes: Vec<NodeId>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct UpdateOperation {
|
||||||
|
path: Position,
|
||||||
|
attributes: NodeAttributes,
|
||||||
|
old_attributes: NodeAttributes,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct DeleteOperation {
|
||||||
|
path: Position,
|
||||||
|
nodes: Vec<NodeId>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct TextEditOperation {
|
||||||
|
path: Position,
|
||||||
|
delta: TextDelta,
|
||||||
|
inverted: TextDelta,
|
||||||
|
}
|
||||||
@ -1,8 +1,10 @@
|
|||||||
mod attributes;
|
mod attributes;
|
||||||
mod document;
|
mod document;
|
||||||
|
mod document_operation;
|
||||||
mod node;
|
mod node;
|
||||||
mod position;
|
mod position;
|
||||||
|
|
||||||
pub use attributes::*;
|
pub use attributes::*;
|
||||||
pub use document::*;
|
pub use document::*;
|
||||||
|
pub use document_operation::*;
|
||||||
pub use node::*;
|
pub use node::*;
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
#[derive(Clone)]
|
||||||
pub struct Position(pub Vec<usize>);
|
pub struct Position(pub Vec<usize>);
|
||||||
|
|
||||||
impl Position {
|
impl Position {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user