Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

fix: tab & enter test

Lucas.Xu5421c156c3a7
diff --git a/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/tab_handler.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/tab_handler.dart
index d0d594d41e..0291fc34a5 100644
--- a/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/tab_handler.dart
+++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/tab_handler.dart
@@ -13,15 +13,19 @@ ShortcutEventHandler tabHandler = (editorState, event) {
final textNode = textNodes.first;
final previous = textNode.previous;
- if (textNode.subtype != BuiltInAttributeKey.bulletedList ||
- previous == null ||
- previous.subtype != BuiltInAttributeKey.bulletedList) {
+
+ if (textNode.subtype != BuiltInAttributeKey.bulletedList) {
TransactionBuilder(editorState)
..insertText(textNode, selection.end.offset, ' ' * 4)
..commit();
return KeyEventResult.handled;
}
+ if (previous == null ||
+ previous.subtype != BuiltInAttributeKey.bulletedList) {
+ return KeyEventResult.ignored;
+ }
+
final path = previous.path + [previous.children.length];
final afterSelection = Selection(
start: selection.start.copyWith(path: path),
diff --git a/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler_test.dart
index cb2d10ea2f..916541025d 100644
--- a/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler_test.dart
+++ b/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler_test.dart
@@ -2,7 +2,6 @@ import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import '../../infra/test_editor.dart';
-import 'package:appflowy_editor/src/document/built_in_attribute_keys.dart';
void main() async {
setUpAll(() {
@@ -171,13 +170,27 @@ Future<void> _testStyleNeedToBeCopy(WidgetTester tester, String style) async {
LogicalKeyboardKey.enter,
);
expect(editor.documentSelection, Selection.single(path: [4], startOffset: 0));
- 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);
+ if ([BuiltInAttributeKey.heading, BuiltInAttributeKey.quote]
+ .contains(style)) {
+ 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(
diff --git a/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/tab_handler_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/tab_handler_test.dart
index 1374869deb..641282c55f 100644
--- a/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/tab_handler_test.dart
+++ b/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/tab_handler_test.dart
@@ -15,23 +15,24 @@ void main() async {
..insertTextNode(text)
..insertTextNode(text);
await editor.startTesting();
- final document = editor.document;
var selection = Selection.single(path: [0], startOffset: 0);
await editor.updateSelection(selection);
await editor.pressLogicKey(LogicalKeyboardKey.tab);
- // nothing happens
- expect(editor.documentSelection, selection);
- expect(editor.document.toJson(), document.toJson());
+ expect(
+ editor.documentSelection,
+ Selection.single(path: [0], startOffset: 4),
+ );
selection = Selection.single(path: [1], startOffset: 0);
await editor.updateSelection(selection);
await editor.pressLogicKey(LogicalKeyboardKey.tab);
- // nothing happens
- expect(editor.documentSelection, selection);
- expect(editor.document.toJson(), document.toJson());
+ expect(
+ editor.documentSelection,
+ Selection.single(path: [1], startOffset: 4),
+ );
});
testWidgets('press tab in bulleted list', (tester) async {
@@ -63,7 +64,10 @@ void main() async {
await editor.pressLogicKey(LogicalKeyboardKey.tab);
// nothing happens
- expect(editor.documentSelection, selection);
+ expect(
+ editor.documentSelection,
+ Selection.single(path: [0], startOffset: 0),
+ );
expect(editor.document.toJson(), document.toJson());
// Before