Handle multiple image inserts

pull/13/head
singerdmx 4 years ago
parent 4e2f28a18e
commit ce77729968
  1. 3
      CHANGELOG.md
  2. 19
      lib/models/documents/document.dart

@ -16,3 +16,6 @@
## [0.0.6]
* More toolbar functionality.
## [0.0.7]
* Handle multiple image inserts.

@ -35,8 +35,7 @@ class Document {
Stream<Tuple3<Delta, Delta, ChangeSource>> get changes => _observer.stream;
Document() : _delta = Delta()
..insert('\n') {
Document() : _delta = Delta()..insert('\n') {
_loadDocument(_delta);
}
@ -194,17 +193,21 @@ class Document {
assert((doc.last.data as String).endsWith('\n'));
int offset = 0;
for (final op in doc.toList()) {
if (!op.isInsert) {
throw ArgumentError.value(doc,
'Document Delta can only contain insert operations but ${op.key} found.');
}
final style =
op.attributes != null ? Style.fromJson(op.attributes) : null;
if (op.isInsert) {
final data = _normalize(op.data);
_root.insert(offset, data, style);
} else {
throw ArgumentError.value(doc,
'Document Delta can only contain insert operations but ${op
.key} found.');
}
offset += op.length;
if (data is! String) {
// This case is 'insert embed'
// automatically append '\n' for image
_root.insert(offset, '\n', null);
offset++;
}
}
final node = _root.last;
if (node is Line &&

Loading…
Cancel
Save