From 3c7fcb3c6693285330cc9d28cd519a033268d12f Mon Sep 17 00:00:00 2001 From: X Code Date: Sun, 30 Jan 2022 21:03:54 -0800 Subject: [PATCH] Add comments --- lib/src/models/documents/document.dart | 2 ++ lib/src/models/documents/nodes/block.dart | 1 + lib/src/models/documents/nodes/line.dart | 1 + 3 files changed, 4 insertions(+) diff --git a/lib/src/models/documents/document.dart b/lib/src/models/documents/document.dart index 0283a011..5a8b840e 100644 --- a/lib/src/models/documents/document.dart +++ b/lib/src/models/documents/document.dart @@ -225,6 +225,8 @@ class Document { op.attributes != null ? Style.fromJson(op.attributes) : null; if (op.isInsert) { + // Must normalize data before inserting into the document, makes sure + // that any embedded objects are converted into EmbeddableObject type. _root.insert(offset, _normalize(op.data), style); } else if (op.isDelete) { _root.delete(offset, op.length); diff --git a/lib/src/models/documents/nodes/block.dart b/lib/src/models/documents/nodes/block.dart index 095f1183..ed5a4c75 100644 --- a/lib/src/models/documents/nodes/block.dart +++ b/lib/src/models/documents/nodes/block.dart @@ -23,6 +23,7 @@ class Block extends Container { @override Delta toDelta() { + // Line nodes take care of incorporating block style into their delta. return children .map((child) => child.toDelta()) .fold(Delta(), (a, b) => a.concat(b)); diff --git a/lib/src/models/documents/nodes/line.dart b/lib/src/models/documents/nodes/line.dart index 9e7094db..9059b321 100644 --- a/lib/src/models/documents/nodes/line.dart +++ b/lib/src/models/documents/nodes/line.dart @@ -268,6 +268,7 @@ class Line extends Container { unlink(); block.insertAfter(this); } else { + /// need to split this block into two as [line] is in the middle. final before = block.clone() as Block; block.insertBefore(before);