|
@@ -29,24 +29,34 @@ extension TextNodeExtension on TextNode {
|
|
|
}
|
|
|
|
|
|
bool allSatisfyLinkInSelection(Selection selection) =>
|
|
|
- allSatisfyInSelection(StyleKey.href, null, selection);
|
|
|
+ allSatisfyInSelection(StyleKey.href, selection, (value) {
|
|
|
+ return value != null;
|
|
|
+ });
|
|
|
|
|
|
bool allSatisfyBoldInSelection(Selection selection) =>
|
|
|
- allSatisfyInSelection(StyleKey.bold, true, selection);
|
|
|
+ allSatisfyInSelection(StyleKey.bold, selection, (value) {
|
|
|
+ return value == true;
|
|
|
+ });
|
|
|
|
|
|
bool allSatisfyItalicInSelection(Selection selection) =>
|
|
|
- allSatisfyInSelection(StyleKey.italic, true, selection);
|
|
|
+ allSatisfyInSelection(StyleKey.italic, selection, (value) {
|
|
|
+ return value == true;
|
|
|
+ });
|
|
|
|
|
|
bool allSatisfyUnderlineInSelection(Selection selection) =>
|
|
|
- allSatisfyInSelection(StyleKey.underline, true, selection);
|
|
|
+ allSatisfyInSelection(StyleKey.underline, selection, (value) {
|
|
|
+ return value == true;
|
|
|
+ });
|
|
|
|
|
|
bool allSatisfyStrikethroughInSelection(Selection selection) =>
|
|
|
- allSatisfyInSelection(StyleKey.strikethrough, true, selection);
|
|
|
+ allSatisfyInSelection(StyleKey.strikethrough, selection, (value) {
|
|
|
+ return value == true;
|
|
|
+ });
|
|
|
|
|
|
bool allSatisfyInSelection(
|
|
|
String styleKey,
|
|
|
- dynamic value,
|
|
|
Selection selection,
|
|
|
+ bool Function(dynamic value) compare,
|
|
|
) {
|
|
|
final ops = delta.whereType<TextInsert>();
|
|
|
final startOffset =
|
|
@@ -62,7 +72,7 @@ extension TextNodeExtension on TextNode {
|
|
|
if (start < endOffset && start + length > startOffset) {
|
|
|
if (op.attributes == null ||
|
|
|
!op.attributes!.containsKey(styleKey) ||
|
|
|
- op.attributes![styleKey] != value) {
|
|
|
+ !compare(op.attributes![styleKey])) {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
@@ -116,13 +126,15 @@ extension TextNodesExtension on List<TextNode> {
|
|
|
bool allSatisfyInSelection(
|
|
|
String styleKey,
|
|
|
Selection selection,
|
|
|
- dynamic value,
|
|
|
+ dynamic matchValue,
|
|
|
) {
|
|
|
if (isEmpty) {
|
|
|
return false;
|
|
|
}
|
|
|
if (length == 1) {
|
|
|
- return first.allSatisfyInSelection(styleKey, value, selection);
|
|
|
+ return first.allSatisfyInSelection(styleKey, selection, (value) {
|
|
|
+ return value == matchValue;
|
|
|
+ });
|
|
|
} else {
|
|
|
for (var i = 0; i < length; i++) {
|
|
|
final node = this[i];
|
|
@@ -142,7 +154,9 @@ extension TextNodesExtension on List<TextNode> {
|
|
|
end: Position(path: node.path, offset: node.toRawString().length),
|
|
|
);
|
|
|
}
|
|
|
- if (!node.allSatisfyInSelection(styleKey, value, newSelection)) {
|
|
|
+ if (!node.allSatisfyInSelection(styleKey, newSelection, (value) {
|
|
|
+ return value == matchValue;
|
|
|
+ })) {
|
|
|
return false;
|
|
|
}
|
|
|
}
|