fix insert image

pull/13/head
li3317 4 years ago
parent a8ee798a0d
commit 89de513df2
  1. 8
      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));

Loading…
Cancel
Save