Skip to content

Commit fdde24a

Browse files
[Quill][Bug] - Fix exception when serializing empty document (Resolves #2635) (#2636)
1 parent 652f8ee commit fdde24a

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

super_editor_quill/lib/src/serializing/serializers.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ class TextBlockDeltaSerializer implements DeltaSerializer {
232232
// We didn't have a natural trailing newline. Insert a newline as per the
233233
// Delta spec.
234234
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)) {
237237
deltas.operations[deltas.operations.length - 1] = newlineDelta.mergeWith(previousDelta);
238238
} else {
239239
deltas.operations.add(newlineDelta);

super_editor_quill/test/serializing_test.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,23 @@ import 'test_documents.dart';
1010

1111
void main() {
1212
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+
1330
group("text >", () {
1431
test("multiline header", () {
1532
// Note: The official Quill editor doesn't seem to support multiline

0 commit comments

Comments
 (0)