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:
parent
096544d6a3
commit
a309a9c82c
@ -2,14 +2,14 @@ import 'package:appflowy_editor/appflowy_editor.dart';
|
||||
|
||||
abstract class Operation {
|
||||
factory Operation.fromJson(Map<String, dynamic> map) {
|
||||
String t = map["type"] as String;
|
||||
if (t == "insert-operation") {
|
||||
String t = map["op"] as String;
|
||||
if (t == "insert") {
|
||||
return InsertOperation.fromJson(map);
|
||||
} else if (t == "update-operation") {
|
||||
} else if (t == "update") {
|
||||
return UpdateOperation.fromJson(map);
|
||||
} else if (t == "delete-operation") {
|
||||
} else if (t == "delete") {
|
||||
return DeleteOperation.fromJson(map);
|
||||
} else if (t == "text-edit-operation") {
|
||||
} else if (t == "text-edit") {
|
||||
return TextEditOperation.fromJson(map);
|
||||
}
|
||||
|
||||
@ -51,7 +51,7 @@ class InsertOperation extends Operation {
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
"type": "insert-operation",
|
||||
"op": "insert",
|
||||
"path": path.toList(),
|
||||
"nodes": nodes.map((n) => n.toJson()),
|
||||
};
|
||||
@ -95,7 +95,7 @@ class UpdateOperation extends Operation {
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
"type": "update-operation",
|
||||
"op": "update",
|
||||
"path": path.toList(),
|
||||
"attributes": {...attributes},
|
||||
"oldAttributes": {...oldAttributes},
|
||||
@ -132,7 +132,7 @@ class DeleteOperation extends Operation {
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
"type": "delete-operation",
|
||||
"op": "delete",
|
||||
"path": path.toList(),
|
||||
"nodes": nodes.map((n) => n.toJson()),
|
||||
};
|
||||
@ -171,7 +171,7 @@ class TextEditOperation extends Operation {
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
"type": "text-edit-operation",
|
||||
"op": "text-edit",
|
||||
"path": path.toList(),
|
||||
"delta": delta.toJson(),
|
||||
"invert": inverted.toJson(),
|
||||
|
@ -84,7 +84,7 @@ void main() {
|
||||
expect(transaction.toJson(), {
|
||||
"operations": [
|
||||
{
|
||||
"type": "insert-operation",
|
||||
"op": "insert",
|
||||
"path": [0],
|
||||
"nodes": [item1.toJson()],
|
||||
}
|
||||
@ -107,7 +107,7 @@ void main() {
|
||||
expect(transaction.toJson(), {
|
||||
"operations": [
|
||||
{
|
||||
"type": "delete-operation",
|
||||
"op": "delete",
|
||||
"path": [0],
|
||||
"nodes": [item1.toJson()],
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user