mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: CI format error
This commit is contained in:
parent
61d181b228
commit
c61b4d0865
@ -1,6 +1,7 @@
|
||||
use crate::core::document::position::Position;
|
||||
use crate::core::{NodeAttributes, NodeData, TextDelta};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum DocumentOperation {
|
||||
Insert(InsertOperation),
|
||||
Update(UpdateOperation),
|
||||
@ -31,24 +32,31 @@ impl DocumentOperation {
|
||||
}),
|
||||
}
|
||||
}
|
||||
pub fn transform(_a: &DocumentOperation, b: &DocumentOperation) -> DocumentOperation {
|
||||
b.clone()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct InsertOperation {
|
||||
pub path: Position,
|
||||
pub nodes: Vec<NodeData>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct UpdateOperation {
|
||||
pub path: Position,
|
||||
pub attributes: NodeAttributes,
|
||||
pub old_attributes: NodeAttributes,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct DeleteOperation {
|
||||
pub path: Position,
|
||||
pub nodes: Vec<NodeData>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct TextEditOperation {
|
||||
pub path: Position,
|
||||
pub delta: TextDelta,
|
||||
|
@ -5,6 +5,38 @@ impl Position {
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.0.is_empty()
|
||||
}
|
||||
pub fn len(&self) -> usize {
|
||||
self.0.len()
|
||||
}
|
||||
}
|
||||
|
||||
impl Position {
|
||||
// delta is default to be 1
|
||||
pub fn transform(pre_insert_path: &Position, b: &Position, delta: usize) -> Position {
|
||||
if pre_insert_path.len() > b.len() {
|
||||
return b.clone();
|
||||
}
|
||||
if pre_insert_path.is_empty() || b.is_empty() {
|
||||
return b.clone();
|
||||
}
|
||||
// check the prefix
|
||||
for i in 0..(pre_insert_path.len()) {
|
||||
if pre_insert_path.0[i] != b.0[i] {
|
||||
return b.clone();
|
||||
}
|
||||
}
|
||||
let mut prefix: Vec<usize> = pre_insert_path.0[0..(pre_insert_path.len() - 1)].into();
|
||||
let mut suffix: Vec<usize> = b.0[pre_insert_path.0.len()..].into();
|
||||
let prev_insert_last: usize = *pre_insert_path.0.last().unwrap();
|
||||
let b_at_index = b.0[pre_insert_path.0.len() - 1];
|
||||
if prev_insert_last <= b_at_index {
|
||||
prefix.push(b_at_index + delta);
|
||||
} else {
|
||||
prefix.push(b_at_index);
|
||||
}
|
||||
prefix.append(&mut suffix);
|
||||
return Position(prefix);
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Vec<usize>> for Position {
|
||||
|
@ -1,6 +1,8 @@
|
||||
use std::collections::HashMap;
|
||||
use crate::core::document::position::Position;
|
||||
use crate::core::{DeleteOperation, DocumentOperation, DocumentTree, InsertOperation, NodeAttributes, NodeData, UpdateOperation};
|
||||
use crate::core::{
|
||||
DeleteOperation, DocumentOperation, DocumentTree, InsertOperation, NodeAttributes, NodeData, UpdateOperation,
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub struct Transaction {
|
||||
pub operations: Vec<DocumentOperation>,
|
||||
|
@ -1,5 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
use lib_ot::core::{DocumentTree, NodeData, TransactionBuilder};
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[test]
|
||||
fn main() {
|
||||
@ -21,9 +21,10 @@ fn test_documents() {
|
||||
assert_eq!(node_data.node_type, "text");
|
||||
|
||||
let mut tb = TransactionBuilder::new(&document);
|
||||
tb.update_attributes(&vec![0].into(), HashMap::from([
|
||||
("subtype".into(), Some("bullet-list".into())),
|
||||
]));
|
||||
tb.update_attributes(
|
||||
&vec![0].into(),
|
||||
HashMap::from([("subtype".into(), Some("bullet-list".into()))]),
|
||||
);
|
||||
let transaction = tb.finalize();
|
||||
document.apply(transaction);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user