mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
test: update text style by command + x
This commit is contained in:
parent
6b312b4f8f
commit
88ae437379
@ -41,6 +41,30 @@ extension TextNodeExtension on TextNode {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool allNotSatisfyInSelection(String styleKey, Selection selection) {
|
||||||
|
final ops = delta.whereType<TextInsert>();
|
||||||
|
final startOffset =
|
||||||
|
selection.isBackward ? selection.start.offset : selection.end.offset;
|
||||||
|
final endOffset =
|
||||||
|
selection.isBackward ? selection.end.offset : selection.start.offset;
|
||||||
|
var start = 0;
|
||||||
|
for (final op in ops) {
|
||||||
|
if (start >= endOffset) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
final length = op.length;
|
||||||
|
if (start < endOffset && start + length > startOffset) {
|
||||||
|
if (op.attributes != null &&
|
||||||
|
op.attributes!.containsKey(styleKey) &&
|
||||||
|
op.attributes![styleKey] == true) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
start += length;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension TextNodesExtension on List<TextNode> {
|
extension TextNodesExtension on List<TextNode> {
|
||||||
|
@ -18,7 +18,6 @@ void main() async {
|
|||||||
LogicalKeyboardKey.keyB,
|
LogicalKeyboardKey.keyB,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('Presses Command + I to update text style', (tester) async {
|
testWidgets('Presses Command + I to update text style', (tester) async {
|
||||||
await _testUpdateTextStyleByCommandX(
|
await _testUpdateTextStyleByCommandX(
|
||||||
tester,
|
tester,
|
||||||
@ -26,7 +25,6 @@ void main() async {
|
|||||||
LogicalKeyboardKey.keyI,
|
LogicalKeyboardKey.keyI,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('Presses Command + U to update text style', (tester) async {
|
testWidgets('Presses Command + U to update text style', (tester) async {
|
||||||
await _testUpdateTextStyleByCommandX(
|
await _testUpdateTextStyleByCommandX(
|
||||||
tester,
|
tester,
|
||||||
@ -34,7 +32,6 @@ void main() async {
|
|||||||
LogicalKeyboardKey.keyU,
|
LogicalKeyboardKey.keyU,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('Presses Command + S to update text style', (tester) async {
|
testWidgets('Presses Command + S to update text style', (tester) async {
|
||||||
await _testUpdateTextStyleByCommandX(
|
await _testUpdateTextStyleByCommandX(
|
||||||
tester,
|
tester,
|
||||||
@ -83,5 +80,49 @@ Future<void> _testUpdateTextStyleByCommandX(
|
|||||||
isMetaPressed: true,
|
isMetaPressed: true,
|
||||||
);
|
);
|
||||||
textNode = editor.nodeAtPath([1]) as TextNode;
|
textNode = editor.nodeAtPath([1]) as TextNode;
|
||||||
expect(textNode.allSatisfyInSelection(matchStyle, selection), false);
|
expect(textNode.allNotSatisfyInSelection(matchStyle, selection), true);
|
||||||
|
|
||||||
|
selection = Selection(
|
||||||
|
start: Position(path: [0], offset: 0),
|
||||||
|
end: Position(path: [2], offset: text.length),
|
||||||
|
);
|
||||||
|
await editor.updateSelection(selection);
|
||||||
|
await editor.pressLogicKey(
|
||||||
|
key,
|
||||||
|
isShiftPressed: key == LogicalKeyboardKey.keyS,
|
||||||
|
isMetaPressed: true,
|
||||||
|
);
|
||||||
|
var nodes = editor.editorState.service.selectionService.currentSelectedNodes
|
||||||
|
.whereType<TextNode>();
|
||||||
|
expect(nodes.length, 3);
|
||||||
|
for (final node in nodes) {
|
||||||
|
expect(
|
||||||
|
node.allSatisfyInSelection(
|
||||||
|
matchStyle,
|
||||||
|
Selection.single(
|
||||||
|
path: node.path, startOffset: 0, endOffset: text.length),
|
||||||
|
),
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await editor.updateSelection(selection);
|
||||||
|
await editor.pressLogicKey(
|
||||||
|
key,
|
||||||
|
isShiftPressed: key == LogicalKeyboardKey.keyS,
|
||||||
|
isMetaPressed: true,
|
||||||
|
);
|
||||||
|
nodes = editor.editorState.service.selectionService.currentSelectedNodes
|
||||||
|
.whereType<TextNode>();
|
||||||
|
expect(nodes.length, 3);
|
||||||
|
for (final node in nodes) {
|
||||||
|
expect(
|
||||||
|
node.allNotSatisfyInSelection(
|
||||||
|
matchStyle,
|
||||||
|
Selection.single(
|
||||||
|
path: node.path, startOffset: 0, endOffset: text.length),
|
||||||
|
),
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user