Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
fix: minor issues
Vincent Chana309a9c82cc2
diff --git a/frontend/app_flowy/packages/appflowy_editor/lib/src/operation/operation.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/operation/operation.dartindex 456be06766..af2ec831d4 100644--- a/frontend/app_flowy/packages/appflowy_editor/lib/src/operation/operation.dart+++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/operation/operation.dart@@ -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 {@overrideMap<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 {@overrideMap<String, dynamic> toJson() {return {- "type": "update-operation",+ "op": "update","path": path.toList(),"attributes": {...attributes},"oldAttributes": {...oldAttributes},@@ -132,7 +132,7 @@ class DeleteOperation extends Operation {@overrideMap<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 {@overrideMap<String, dynamic> toJson() {return {- "type": "text-edit-operation",+ "op": "text-edit","path": path.toList(),"delta": delta.toJson(),"invert": inverted.toJson(),diff --git a/frontend/app_flowy/packages/appflowy_editor/test/legacy/operation_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/legacy/operation_test.dartindex 1f44ebfd3c..6c20ebd134 100644--- a/frontend/app_flowy/packages/appflowy_editor/test/legacy/operation_test.dart+++ b/frontend/app_flowy/packages/appflowy_editor/test/legacy/operation_test.dart@@ -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()],}diff --git a/shared-lib/lib-ot/src/core/document/document_operation.rs b/shared-lib/lib-ot/src/core/document/document_operation.rsindex caca29e110..4d9d3617eb 100644--- a/shared-lib/lib-ot/src/core/document/document_operation.rs+++ b/shared-lib/lib-ot/src/core/document/document_operation.rs@@ -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":[]}"#);}}diff --git a/shared-lib/lib-ot/src/core/document/position.rs b/shared-lib/lib-ot/src/core/document/position.rsindex 521d0e9a60..b98edd97f4 100644--- a/shared-lib/lib-ot/src/core/document/position.rs+++ b/shared-lib/lib-ot/src/core/document/position.rs@@ -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);}