Skip to content

Commit a40fd24

Browse files
committed
fix: ensure delta ended with new line when building doc from delta
1 parent 2a97d99 commit a40fd24

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/src/editor_controller.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ extension BBCodeExt on BBCodeEditorController {
4242
void setDocumentFromDelta(Delta delta) {
4343
if (delta.isEmpty) {
4444
delta.insert('\n');
45+
} else {
46+
// Make sure delta ended with new line.
47+
final lastOp = delta.operations.lastOrNull;
48+
final lastOpData = lastOp?.data;
49+
if (lastOp == null || lastOp.data == null || lastOpData is! String || !lastOpData.endsWith('\n')) {
50+
delta.operations.add(Operation.insert('\n'));
51+
}
4552
}
4653

4754
document = Document.fromDelta(delta);

0 commit comments

Comments
 (0)