File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -232,8 +232,8 @@ class TextBlockDeltaSerializer implements DeltaSerializer {
232
232
// We didn't have a natural trailing newline. Insert a newline as per the
233
233
// Delta spec.
234
234
final newlineDelta = Operation .insert ("\n " , blockFormats.isNotEmpty ? blockFormats : null );
235
- final previousDelta = deltas.operations[deltas.operations.length - 1 ];
236
- if (newlineDelta.canMergeWith (previousDelta)) {
235
+ final previousDelta = deltas.operations.isNotEmpty ? deltas.operations [deltas.operations.length - 1 ] : null ;
236
+ if (previousDelta != null && newlineDelta.canMergeWith (previousDelta)) {
237
237
deltas.operations[deltas.operations.length - 1 ] = newlineDelta.mergeWith (previousDelta);
238
238
} else {
239
239
deltas.operations.add (newlineDelta);
Original file line number Diff line number Diff line change @@ -10,6 +10,23 @@ import 'test_documents.dart';
10
10
11
11
void main () {
12
12
group ("Delta document serializing >" , () {
13
+ test ("empty document" , () {
14
+ final deltas = MutableDocument (
15
+ nodes: [
16
+ ParagraphNode (
17
+ id: "1" ,
18
+ text: AttributedText ("" ),
19
+ ),
20
+ ],
21
+ ).toQuillDeltas ();
22
+
23
+ final expectedDeltas = Delta .fromJson ([
24
+ {"insert" : "\n " },
25
+ ]);
26
+
27
+ expect (deltas, quillDocumentEquivalentTo (expectedDeltas));
28
+ });
29
+
13
30
group ("text >" , () {
14
31
test ("multiline header" , () {
15
32
// Note: The official Quill editor doesn't seem to support multiline
You can’t perform that action at this time.
0 commit comments