From 5421c156c3a7c6712aef50bcc2656ab46b4b1ca6 Mon Sep 17 00:00:00 2001 From: "Lucas.Xu" Date: Mon, 26 Sep 2022 18:13:45 +0800 Subject: [PATCH] fix: tab & enter test --- .../tab_handler.dart | 10 ++++--- ...thout_shift_in_text_node_handler_test.dart | 27 ++++++++++++++----- .../tab_handler_test.dart | 20 ++++++++------ 3 files changed, 39 insertions(+), 18 deletions(-) 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 _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 _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