Add: test for QuillController clipboard

Dart Formatted
pull/1892/head
Douglas Ward 12 months ago committed by AtlasAutocode
parent b364dd0930
commit 61bce817a7
  1. 46
      lib/src/models/documents/nodes/line.dart

@ -43,7 +43,9 @@ base class Line extends QuillContainer<Leaf?> {
if (parent!.isLast) { if (parent!.isLast) {
return null; return null;
} }
return parent!.next is Block ? (parent!.next as Block).first as Line? : parent!.next as Line?; return parent!.next is Block
? (parent!.next as Block).first as Line?
: parent!.next as Line?;
} }
@override @override
@ -51,7 +53,9 @@ base class Line extends QuillContainer<Leaf?> {
@override @override
Delta toDelta() { Delta toDelta() {
final delta = children.map((child) => child.toDelta()).fold(Delta(), (dynamic a, b) => a.concat(b)); final delta = children
.map((child) => child.toDelta())
.fold(Delta(), (dynamic a, b) => a.concat(b));
var attributes = style; var attributes = style;
if (parent is Block) { if (parent is Block) {
final block = parent as Block; final block = parent as Block;
@ -130,11 +134,17 @@ base class Line extends QuillContainer<Leaf?> {
final isLineFormat = (index + local == thisLength) && local == 1; final isLineFormat = (index + local == thisLength) && local == 1;
if (isLineFormat) { if (isLineFormat) {
assert(style.values.every((attr) => attr.scope == AttributeScope.block || attr.scope == AttributeScope.ignore), 'It is not allowed to apply inline attributes to line itself.'); assert(
style.values.every((attr) =>
attr.scope == AttributeScope.block ||
attr.scope == AttributeScope.ignore),
'It is not allowed to apply inline attributes to line itself.');
_format(style); _format(style);
} else { } else {
// Otherwise forward to children as it's an inline format update. // Otherwise forward to children as it's an inline format update.
assert(style.values.every((attr) => attr.scope == AttributeScope.inline || attr.scope == AttributeScope.ignore)); assert(style.values.every((attr) =>
attr.scope == AttributeScope.inline ||
attr.scope == AttributeScope.ignore));
assert(index + local != thisLength); assert(index + local != thisLength);
super.retain(index, local, style); super.retain(index, local, style);
} }
@ -205,15 +215,21 @@ base class Line extends QuillContainer<Leaf?> {
// Ensure that we're only unwrapping the block only if we unset a single // Ensure that we're only unwrapping the block only if we unset a single
// block format in the `parentStyle` and there are no more block formats // block format in the `parentStyle` and there are no more block formats
// left to unset. // left to unset.
if (blockStyle.value == null && parentStyle.containsKey(blockStyle.key) && parentStyle.length == 1) { if (blockStyle.value == null &&
parentStyle.containsKey(blockStyle.key) &&
parentStyle.length == 1) {
_unwrap(); _unwrap();
} else if (!const MapEquality().equals(newStyle.getBlocksExceptHeader(), parentStyle)) { } else if (!const MapEquality()
.equals(newStyle.getBlocksExceptHeader(), parentStyle)) {
_unwrap(); _unwrap();
// Block style now can contain multiple attributes // Block style now can contain multiple attributes
if (newStyle.attributes.keys.any(Attribute.exclusiveBlockKeys.contains)) { if (newStyle.attributes.keys
parentStyle.removeWhere((key, attr) => Attribute.exclusiveBlockKeys.contains(key)); .any(Attribute.exclusiveBlockKeys.contains)) {
parentStyle.removeWhere(
(key, attr) => Attribute.exclusiveBlockKeys.contains(key));
} }
parentStyle.removeWhere((key, attr) => newStyle?.attributes.keys.contains(key) ?? false); parentStyle.removeWhere(
(key, attr) => newStyle?.attributes.keys.contains(key) ?? false);
final parentStyleToMerge = Style.attr(parentStyle); final parentStyleToMerge = Style.attr(parentStyle);
newStyle = newStyle.mergeAll(parentStyleToMerge); newStyle = newStyle.mergeAll(parentStyleToMerge);
_applyBlockStyles(newStyle); _applyBlockStyles(newStyle);
@ -345,7 +361,8 @@ base class Line extends QuillContainer<Leaf?> {
void handle(Style style) { void handle(Style style) {
for (final attr in result.values) { for (final attr in result.values) {
if (!style.containsKey(attr.key) || (style.attributes[attr.key]?.value != attr.value)) { if (!style.containsKey(attr.key) ||
(style.attributes[attr.key]?.value != attr.value)) {
excluded.add(attr); excluded.add(attr);
} }
} }
@ -380,7 +397,8 @@ base class Line extends QuillContainer<Leaf?> {
/// Returns each node segment's offset in selection /// Returns each node segment's offset in selection
/// with its corresponding style or embed as a list /// with its corresponding style or embed as a list
List<OffsetValue> collectAllIndividualStylesAndEmbed(int offset, int len, {int beg = 0}) { List<OffsetValue> collectAllIndividualStylesAndEmbed(int offset, int len,
{int beg = 0}) {
final local = math.min(length - offset, len); final local = math.min(length - offset, len);
final result = <OffsetValue>[]; final result = <OffsetValue>[];
@ -412,7 +430,8 @@ base class Line extends QuillContainer<Leaf?> {
final remaining = len - local; final remaining = len - local;
if (remaining > 0 && nextLine != null) { if (remaining > 0 && nextLine != null) {
final rest = nextLine!.collectAllIndividualStylesAndEmbed(0, remaining, beg: local + beg); final rest = nextLine!
.collectAllIndividualStylesAndEmbed(0, remaining, beg: local + beg);
result.addAll(rest); result.addAll(rest);
} }
@ -482,7 +501,8 @@ base class Line extends QuillContainer<Leaf?> {
final remaining = len - local; final remaining = len - local;
if (remaining > 0 && nextLine != null) { if (remaining > 0 && nextLine != null) {
final rest = nextLine!.collectAllStylesWithOffsets(0, remaining, beg: local); final rest =
nextLine!.collectAllStylesWithOffsets(0, remaining, beg: local);
result.addAll(rest); result.addAll(rest);
} }

Loading…
Cancel
Save