mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: minor issues
This commit is contained in:
@ -2,26 +2,26 @@ use crate::core::document::position::Position;
|
||||
use crate::core::{NodeAttributes, NodeSubTree, TextDelta};
|
||||
|
||||
#[derive(Clone, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(tag = "type")]
|
||||
#[serde(tag = "op")]
|
||||
pub enum DocumentOperation {
|
||||
#[serde(rename = "insert-operation")]
|
||||
#[serde(rename = "insert")]
|
||||
Insert {
|
||||
path: Position,
|
||||
nodes: Vec<Box<NodeSubTree>>,
|
||||
},
|
||||
#[serde(rename = "update-operation")]
|
||||
#[serde(rename = "update")]
|
||||
Update {
|
||||
path: Position,
|
||||
attributes: NodeAttributes,
|
||||
#[serde(rename = "oldAttributes")]
|
||||
old_attributes: NodeAttributes,
|
||||
},
|
||||
#[serde(rename = "delete-operation")]
|
||||
#[serde(rename = "delete")]
|
||||
Delete {
|
||||
path: Position,
|
||||
nodes: Vec<Box<NodeSubTree>>,
|
||||
},
|
||||
#[serde(rename = "text-edit-operation")]
|
||||
#[serde(rename = "text-edit")]
|
||||
TextEdit {
|
||||
path: Position,
|
||||
delta: TextDelta,
|
||||
@ -166,7 +166,7 @@ mod tests {
|
||||
let result = serde_json::to_string(&insert).unwrap();
|
||||
assert_eq!(
|
||||
result,
|
||||
r#"{"type":"insert-operation","path":[0,1],"nodes":[{"type":"text","attributes":{}}]}"#
|
||||
r#"{"op":"insert","path":[0,1],"nodes":[{"type":"text","attributes":{}}]}"#
|
||||
);
|
||||
}
|
||||
|
||||
@ -184,7 +184,7 @@ mod tests {
|
||||
let result = serde_json::to_string(&insert).unwrap();
|
||||
assert_eq!(
|
||||
result,
|
||||
r#"{"type":"insert-operation","path":[0,1],"nodes":[{"type":"text","attributes":{},"children":[{"type":"text","attributes":{}}]}]}"#
|
||||
r#"{"op":"insert","path":[0,1],"nodes":[{"type":"text","attributes":{},"children":[{"type":"text","attributes":{}}]}]}"#
|
||||
);
|
||||
}
|
||||
|
||||
@ -198,7 +198,7 @@ mod tests {
|
||||
let result = serde_json::to_string(&insert).unwrap();
|
||||
assert_eq!(
|
||||
result,
|
||||
r#"{"type":"update-operation","path":[0,1],"attributes":{},"oldAttributes":{}}"#
|
||||
r#"{"op":"update","path":[0,1],"attributes":{},"oldAttributes":{}}"#
|
||||
);
|
||||
}
|
||||
|
||||
@ -210,9 +210,6 @@ mod tests {
|
||||
inverted: Delta::new(),
|
||||
};
|
||||
let result = serde_json::to_string(&insert).unwrap();
|
||||
assert_eq!(
|
||||
result,
|
||||
r#"{"type":"text-edit-operation","path":[0,1],"delta":[],"inverted":[]}"#
|
||||
);
|
||||
assert_eq!(result, r#"{"op":"text-edit","path":[0,1],"delta":[],"inverted":[]}"#);
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ impl Position {
|
||||
|
||||
impl Position {
|
||||
// delta is default to be 1
|
||||
pub fn transform(pre_insert_path: &Position, b: &Position, delta: i64) -> Position {
|
||||
pub fn transform(pre_insert_path: &Position, b: &Position, offset: i64) -> Position {
|
||||
if pre_insert_path.len() > b.len() {
|
||||
return b.clone();
|
||||
}
|
||||
@ -30,7 +30,7 @@ impl Position {
|
||||
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 as i64) + delta) as usize);
|
||||
prefix.push(((b_at_index as i64) + offset) as usize);
|
||||
} else {
|
||||
prefix.push(b_at_index);
|
||||
}
|
||||
|
Reference in New Issue
Block a user