Skip to content

Commit a309a9c

Browse files
committed
fix: minor issues
1 parent 096544d commit a309a9c

File tree

4 files changed

+22
-25
lines changed

4 files changed

+22
-25
lines changed

frontend/app_flowy/packages/appflowy_editor/lib/src/operation/operation.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import 'package:appflowy_editor/appflowy_editor.dart';
22

33
abstract class Operation {
44
factory Operation.fromJson(Map<String, dynamic> map) {
5-
String t = map["type"] as String;
6-
if (t == "insert-operation") {
5+
String t = map["op"] as String;
6+
if (t == "insert") {
77
return InsertOperation.fromJson(map);
8-
} else if (t == "update-operation") {
8+
} else if (t == "update") {
99
return UpdateOperation.fromJson(map);
10-
} else if (t == "delete-operation") {
10+
} else if (t == "delete") {
1111
return DeleteOperation.fromJson(map);
12-
} else if (t == "text-edit-operation") {
12+
} else if (t == "text-edit") {
1313
return TextEditOperation.fromJson(map);
1414
}
1515

@@ -51,7 +51,7 @@ class InsertOperation extends Operation {
5151
@override
5252
Map<String, dynamic> toJson() {
5353
return {
54-
"type": "insert-operation",
54+
"op": "insert",
5555
"path": path.toList(),
5656
"nodes": nodes.map((n) => n.toJson()),
5757
};
@@ -95,7 +95,7 @@ class UpdateOperation extends Operation {
9595
@override
9696
Map<String, dynamic> toJson() {
9797
return {
98-
"type": "update-operation",
98+
"op": "update",
9999
"path": path.toList(),
100100
"attributes": {...attributes},
101101
"oldAttributes": {...oldAttributes},
@@ -132,7 +132,7 @@ class DeleteOperation extends Operation {
132132
@override
133133
Map<String, dynamic> toJson() {
134134
return {
135-
"type": "delete-operation",
135+
"op": "delete",
136136
"path": path.toList(),
137137
"nodes": nodes.map((n) => n.toJson()),
138138
};
@@ -171,7 +171,7 @@ class TextEditOperation extends Operation {
171171
@override
172172
Map<String, dynamic> toJson() {
173173
return {
174-
"type": "text-edit-operation",
174+
"op": "text-edit",
175175
"path": path.toList(),
176176
"delta": delta.toJson(),
177177
"invert": inverted.toJson(),

frontend/app_flowy/packages/appflowy_editor/test/legacy/operation_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void main() {
8484
expect(transaction.toJson(), {
8585
"operations": [
8686
{
87-
"type": "insert-operation",
87+
"op": "insert",
8888
"path": [0],
8989
"nodes": [item1.toJson()],
9090
}
@@ -107,7 +107,7 @@ void main() {
107107
expect(transaction.toJson(), {
108108
"operations": [
109109
{
110-
"type": "delete-operation",
110+
"op": "delete",
111111
"path": [0],
112112
"nodes": [item1.toJson()],
113113
}

shared-lib/lib-ot/src/core/document/document_operation.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@ use crate::core::document::position::Position;
22
use crate::core::{NodeAttributes, NodeSubTree, TextDelta};
33

44
#[derive(Clone, serde::Serialize, serde::Deserialize)]
5-
#[serde(tag = "type")]
5+
#[serde(tag = "op")]
66
pub enum DocumentOperation {
7-
#[serde(rename = "insert-operation")]
7+
#[serde(rename = "insert")]
88
Insert {
99
path: Position,
1010
nodes: Vec<Box<NodeSubTree>>,
1111
},
12-
#[serde(rename = "update-operation")]
12+
#[serde(rename = "update")]
1313
Update {
1414
path: Position,
1515
attributes: NodeAttributes,
1616
#[serde(rename = "oldAttributes")]
1717
old_attributes: NodeAttributes,
1818
},
19-
#[serde(rename = "delete-operation")]
19+
#[serde(rename = "delete")]
2020
Delete {
2121
path: Position,
2222
nodes: Vec<Box<NodeSubTree>>,
2323
},
24-
#[serde(rename = "text-edit-operation")]
24+
#[serde(rename = "text-edit")]
2525
TextEdit {
2626
path: Position,
2727
delta: TextDelta,
@@ -166,7 +166,7 @@ mod tests {
166166
let result = serde_json::to_string(&insert).unwrap();
167167
assert_eq!(
168168
result,
169-
r#"{"type":"insert-operation","path":[0,1],"nodes":[{"type":"text","attributes":{}}]}"#
169+
r#"{"op":"insert","path":[0,1],"nodes":[{"type":"text","attributes":{}}]}"#
170170
);
171171
}
172172

@@ -184,7 +184,7 @@ mod tests {
184184
let result = serde_json::to_string(&insert).unwrap();
185185
assert_eq!(
186186
result,
187-
r#"{"type":"insert-operation","path":[0,1],"nodes":[{"type":"text","attributes":{},"children":[{"type":"text","attributes":{}}]}]}"#
187+
r#"{"op":"insert","path":[0,1],"nodes":[{"type":"text","attributes":{},"children":[{"type":"text","attributes":{}}]}]}"#
188188
);
189189
}
190190

@@ -198,7 +198,7 @@ mod tests {
198198
let result = serde_json::to_string(&insert).unwrap();
199199
assert_eq!(
200200
result,
201-
r#"{"type":"update-operation","path":[0,1],"attributes":{},"oldAttributes":{}}"#
201+
r#"{"op":"update","path":[0,1],"attributes":{},"oldAttributes":{}}"#
202202
);
203203
}
204204

@@ -210,9 +210,6 @@ mod tests {
210210
inverted: Delta::new(),
211211
};
212212
let result = serde_json::to_string(&insert).unwrap();
213-
assert_eq!(
214-
result,
215-
r#"{"type":"text-edit-operation","path":[0,1],"delta":[],"inverted":[]}"#
216-
);
213+
assert_eq!(result, r#"{"op":"text-edit","path":[0,1],"delta":[],"inverted":[]}"#);
217214
}
218215
}

shared-lib/lib-ot/src/core/document/position.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ impl Position {
1212

1313
impl Position {
1414
// delta is default to be 1
15-
pub fn transform(pre_insert_path: &Position, b: &Position, delta: i64) -> Position {
15+
pub fn transform(pre_insert_path: &Position, b: &Position, offset: i64) -> Position {
1616
if pre_insert_path.len() > b.len() {
1717
return b.clone();
1818
}
@@ -30,7 +30,7 @@ impl Position {
3030
let prev_insert_last: usize = *pre_insert_path.0.last().unwrap();
3131
let b_at_index = b.0[pre_insert_path.0.len() - 1];
3232
if prev_insert_last <= b_at_index {
33-
prefix.push(((b_at_index as i64) + delta) as usize);
33+
prefix.push(((b_at_index as i64) + offset) as usize);
3434
} else {
3535
prefix.push(b_at_index);
3636
}

0 commit comments

Comments
 (0)