remove newline on concat

pull/502/head
Andriy Trubchanin 4 years ago
parent 35c9f6bb0e
commit 7290643acb
  1. 21
      lib/src/models/quill_delta.dart

@ -608,9 +608,28 @@ class Delta {
}
}
/// Removes trailing '\n'
void _trimNewLine() {
if (isNotEmpty) {
final lastOp = _operations.last;
final lastOpData = lastOp.data;
if (lastOpData is String && lastOpData.endsWith('\n')) {
_operations.removeLast();
if (lastOpData.length > 1) {
insert(lastOpData.substring(0, lastOpData.length - 1),
lastOp.attributes);
}
}
}
}
/// Concatenates [other] with this delta and returns the result.
Delta concat(Delta other) {
Delta concat(Delta other, {bool trimNewLine = false}) {
final result = Delta.from(this);
if (trimNewLine) {
result._trimNewLine();
}
if (other.isNotEmpty) {
// In case first operation of other can be merged with last operation in
// our list.

Loading…
Cancel
Save