diff --git a/lib/models/documents/document.dart b/lib/models/documents/document.dart index fc5634b8..a9eb1701 100644 --- a/lib/models/documents/document.dart +++ b/lib/models/documents/document.dart @@ -173,12 +173,18 @@ class Document { for (int i = 0; i < ops.length; i++) { Operation op = ops[i]; res.push(op); + bool nextOpIsImage = i + 1 < ops.length && + ops[i + 1].isInsert && + ops[i + 1].data is !String; + if (nextOpIsImage && !(op.data as String).endsWith('\n')){ + res.push(Operation.insert('\n', null)); + } // Currently embed is equivalent to image and hence `is! String` bool opInsertImage = op.isInsert && op.data is! String; bool nextOpIsLineBreak = i + 1 < ops.length && ops[i + 1].isInsert && ops[i + 1].data is String && - (ops[i + 1].data as String) == '\n'; + (ops[i + 1].data as String).startsWith('\n'); if (opInsertImage && (i + 1 == ops.length - 1 || !nextOpIsLineBreak)) { // automatically append '\n' for image res.push(Operation.insert('\n', null));