remove newline on concat (#502)

pull/505/head^2
Andy Trand 3 years ago committed by GitHub
parent 4694189a6c
commit 931f7e6513
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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