Skip to content

Commit ed4c295

Browse files
author
CatHood0
committed
Fix: sealed insert exception when insert a newline after a embed
1 parent a63c465 commit ed4c295

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.1.5
2+
3+
* Fix: "cannot insert line when paragraph is sealed" exception when will insert a new line after a embed.
4+
15
## 1.1.4
26

37
* Fix: issue where mergers does not works as expected by @CatHood0 in https://github.com/CatHood0/flutter_quill_delta_easy_parser/pull/3

lib/easy_parser/document_parser.dart

+8
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,14 @@ class DocumentParser {
183183
return;
184184
}
185185
if (!ignoreAllNewLines) {
186+
if (lastParagraph.isEmbed || lastParagraph.isNewLine) {
187+
_document.insert(
188+
Paragraph.newLine(
189+
blockAttributes: operation.attributes,
190+
),
191+
);
192+
return;
193+
}
186194
lastParagraph.insertEmptyLine();
187195
}
188196
}

test/flutter_quill_delta_easy_parser_test.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ void main() {
66
test('Should convert image to paragraph embed', () {
77
final Delta delta = Delta()
88
..insert({'image': '/device/user/to/path/file.jpg'})
9-
..insert('\n');
9+
..insert('\n', {'align': 'center'});
1010

1111
final Document expectedDocument = Document(paragraphs: [
1212
Paragraph.fromRawEmbed(
@@ -311,13 +311,13 @@ void _execExpects(Document? parsedDocument, Document expectedDocument) {
311311
expect(
312312
parsedDocument?.paragraphs[i].blockAttributes,
313313
expectedDocument.paragraphs[i].blockAttributes,
314-
reason: 'Block difference at paragraph($i).\n'
314+
reason: 'Block difference at paragraph(index: $i).\n'
315315
'Parsed: ${parsedDocument?.paragraphs[i].blockAttributes},\nExpected: ${expectedDocument.paragraphs[i].blockAttributes}',
316316
);
317317
expect(
318318
parsedDocument?.paragraphs[i].type,
319319
expectedDocument.paragraphs[i].type,
320-
reason: 'ParagraphType difference at paragraph($i).\n'
320+
reason: 'ParagraphType difference at paragraph(index: $i).\n'
321321
'Parsed: "${parsedDocument?.paragraphs[i].type}",\nExpected: "${expectedDocument.paragraphs[i].type}"',
322322
);
323323
}

0 commit comments

Comments
 (0)