mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: tab & enter test
This commit is contained in:
parent
ff9cf905fa
commit
5421c156c3
@ -13,15 +13,19 @@ ShortcutEventHandler tabHandler = (editorState, event) {
|
|||||||
|
|
||||||
final textNode = textNodes.first;
|
final textNode = textNodes.first;
|
||||||
final previous = textNode.previous;
|
final previous = textNode.previous;
|
||||||
if (textNode.subtype != BuiltInAttributeKey.bulletedList ||
|
|
||||||
previous == null ||
|
if (textNode.subtype != BuiltInAttributeKey.bulletedList) {
|
||||||
previous.subtype != BuiltInAttributeKey.bulletedList) {
|
|
||||||
TransactionBuilder(editorState)
|
TransactionBuilder(editorState)
|
||||||
..insertText(textNode, selection.end.offset, ' ' * 4)
|
..insertText(textNode, selection.end.offset, ' ' * 4)
|
||||||
..commit();
|
..commit();
|
||||||
return KeyEventResult.handled;
|
return KeyEventResult.handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (previous == null ||
|
||||||
|
previous.subtype != BuiltInAttributeKey.bulletedList) {
|
||||||
|
return KeyEventResult.ignored;
|
||||||
|
}
|
||||||
|
|
||||||
final path = previous.path + [previous.children.length];
|
final path = previous.path + [previous.children.length];
|
||||||
final afterSelection = Selection(
|
final afterSelection = Selection(
|
||||||
start: selection.start.copyWith(path: path),
|
start: selection.start.copyWith(path: path),
|
||||||
|
@ -2,7 +2,6 @@ import 'package:appflowy_editor/appflowy_editor.dart';
|
|||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import '../../infra/test_editor.dart';
|
import '../../infra/test_editor.dart';
|
||||||
import 'package:appflowy_editor/src/document/built_in_attribute_keys.dart';
|
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
setUpAll(() {
|
setUpAll(() {
|
||||||
@ -171,13 +170,27 @@ Future<void> _testStyleNeedToBeCopy(WidgetTester tester, String style) async {
|
|||||||
LogicalKeyboardKey.enter,
|
LogicalKeyboardKey.enter,
|
||||||
);
|
);
|
||||||
expect(editor.documentSelection, Selection.single(path: [4], startOffset: 0));
|
expect(editor.documentSelection, Selection.single(path: [4], startOffset: 0));
|
||||||
expect(editor.nodeAtPath([4])?.subtype, style);
|
|
||||||
|
|
||||||
await editor.pressLogicKey(
|
if ([BuiltInAttributeKey.heading, BuiltInAttributeKey.quote]
|
||||||
LogicalKeyboardKey.enter,
|
.contains(style)) {
|
||||||
);
|
expect(editor.nodeAtPath([4])?.subtype, null);
|
||||||
expect(editor.documentSelection, Selection.single(path: [4], startOffset: 0));
|
|
||||||
expect(editor.nodeAtPath([4])?.subtype, null);
|
await editor.pressLogicKey(
|
||||||
|
LogicalKeyboardKey.enter,
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
editor.documentSelection, Selection.single(path: [5], startOffset: 0));
|
||||||
|
expect(editor.nodeAtPath([5])?.subtype, null);
|
||||||
|
} else {
|
||||||
|
expect(editor.nodeAtPath([4])?.subtype, style);
|
||||||
|
|
||||||
|
await editor.pressLogicKey(
|
||||||
|
LogicalKeyboardKey.enter,
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
editor.documentSelection, Selection.single(path: [4], startOffset: 0));
|
||||||
|
expect(editor.nodeAtPath([4])?.subtype, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _testMultipleSelection(
|
Future<void> _testMultipleSelection(
|
||||||
|
@ -15,23 +15,24 @@ void main() async {
|
|||||||
..insertTextNode(text)
|
..insertTextNode(text)
|
||||||
..insertTextNode(text);
|
..insertTextNode(text);
|
||||||
await editor.startTesting();
|
await editor.startTesting();
|
||||||
final document = editor.document;
|
|
||||||
|
|
||||||
var selection = Selection.single(path: [0], startOffset: 0);
|
var selection = Selection.single(path: [0], startOffset: 0);
|
||||||
await editor.updateSelection(selection);
|
await editor.updateSelection(selection);
|
||||||
await editor.pressLogicKey(LogicalKeyboardKey.tab);
|
await editor.pressLogicKey(LogicalKeyboardKey.tab);
|
||||||
|
|
||||||
// nothing happens
|
expect(
|
||||||
expect(editor.documentSelection, selection);
|
editor.documentSelection,
|
||||||
expect(editor.document.toJson(), document.toJson());
|
Selection.single(path: [0], startOffset: 4),
|
||||||
|
);
|
||||||
|
|
||||||
selection = Selection.single(path: [1], startOffset: 0);
|
selection = Selection.single(path: [1], startOffset: 0);
|
||||||
await editor.updateSelection(selection);
|
await editor.updateSelection(selection);
|
||||||
await editor.pressLogicKey(LogicalKeyboardKey.tab);
|
await editor.pressLogicKey(LogicalKeyboardKey.tab);
|
||||||
|
|
||||||
// nothing happens
|
expect(
|
||||||
expect(editor.documentSelection, selection);
|
editor.documentSelection,
|
||||||
expect(editor.document.toJson(), document.toJson());
|
Selection.single(path: [1], startOffset: 4),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('press tab in bulleted list', (tester) async {
|
testWidgets('press tab in bulleted list', (tester) async {
|
||||||
@ -63,7 +64,10 @@ void main() async {
|
|||||||
await editor.pressLogicKey(LogicalKeyboardKey.tab);
|
await editor.pressLogicKey(LogicalKeyboardKey.tab);
|
||||||
|
|
||||||
// nothing happens
|
// nothing happens
|
||||||
expect(editor.documentSelection, selection);
|
expect(
|
||||||
|
editor.documentSelection,
|
||||||
|
Selection.single(path: [0], startOffset: 0),
|
||||||
|
);
|
||||||
expect(editor.document.toJson(), document.toJson());
|
expect(editor.document.toJson(), document.toJson());
|
||||||
|
|
||||||
// Before
|
// Before
|
||||||
|
Loading…
x
Reference in New Issue
Block a user