From c9ee82ec7500443ecb94b758ac3f42a8f1478209 Mon Sep 17 00:00:00 2001 From: "Lucas.Xu" Date: Thu, 10 Aug 2023 17:35:27 +0700 Subject: [PATCH] chore: update editor version to 1.2.3 (#3153) --- .../document_copy_and_paste_test.dart | 47 +++++++++++++++++++ .../document/document_test_runner.dart | 2 + .../integration_test/share_markdown_test.dart | 7 +++ .../util/editor_test_operations.dart | 2 +- .../editor_transaction_adapter.dart | 7 +-- .../callout/callout_block_component.dart | 2 +- .../code_block/code_block_component.dart | 2 +- .../math_equation_block_component.dart | 2 +- .../widgets/auto_completion_node_widget.dart | 2 +- .../outline/outline_block_component.dart | 2 +- .../toggle/toggle_block_component.dart | 2 +- frontend/appflowy_flutter/pubspec.lock | 4 +- frontend/appflowy_flutter/pubspec.yaml | 2 +- 13 files changed, 70 insertions(+), 13 deletions(-) create mode 100644 frontend/appflowy_flutter/integration_test/document/document_copy_and_paste_test.dart diff --git a/frontend/appflowy_flutter/integration_test/document/document_copy_and_paste_test.dart b/frontend/appflowy_flutter/integration_test/document/document_copy_and_paste_test.dart new file mode 100644 index 0000000000..296f71be82 --- /dev/null +++ b/frontend/appflowy_flutter/integration_test/document/document_copy_and_paste_test.dart @@ -0,0 +1,47 @@ +import 'dart:io'; + +import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; + +import '../util/util.dart'; + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + group('copy and paste in document', () { + testWidgets('paste multiple lines at the first line', (tester) async { + await tester.initializeAppFlowy(); + await tester.tapGoButton(); + + // create a new document + await tester.createNewPageWithName(); + + // mock the clipboard + const lines = 3; + AppFlowyClipboard.mockSetData( + AppFlowyClipboardData( + text: List.generate(lines, (index) => 'line $index').join('\n'), + ), + ); + + // paste the text + await tester.simulateKeyEvent( + LogicalKeyboardKey.keyV, + isControlPressed: Platform.isLinux || Platform.isWindows, + isMetaPressed: Platform.isMacOS, + ); + await tester.pumpAndSettle(); + + final editorState = tester.editor.getCurrentEditorState(); + expect(editorState.document.root.children.length, 4); + for (var i = 0; i < lines; i++) { + expect( + editorState.getNodeAtPath([i])!.delta!.toPlainText(), + 'line $i', + ); + } + }); + }); +} diff --git a/frontend/appflowy_flutter/integration_test/document/document_test_runner.dart b/frontend/appflowy_flutter/integration_test/document/document_test_runner.dart index c8d1576b05..1d05ef55d0 100644 --- a/frontend/appflowy_flutter/integration_test/document/document_test_runner.dart +++ b/frontend/appflowy_flutter/integration_test/document/document_test_runner.dart @@ -10,6 +10,7 @@ import 'document_with_inline_page_test.dart' as document_with_inline_page_test; import 'document_with_toggle_list_test.dart' as document_with_toggle_list_test; import 'edit_document_test.dart' as document_edit_test; import 'document_with_outline_block_test.dart' as document_with_outline_block; +import 'document_copy_and_paste_test.dart' as document_copy_and_paste_test; void startTesting() { IntegrationTestWidgetsFlutterBinding.ensureInitialized(); @@ -23,4 +24,5 @@ void startTesting() { document_with_cover_image_test.main(); document_with_outline_block.main(); document_with_toggle_list_test.main(); + document_copy_and_paste_test.main(); } diff --git a/frontend/appflowy_flutter/integration_test/share_markdown_test.dart b/frontend/appflowy_flutter/integration_test/share_markdown_test.dart index 60b430613e..2565c62741 100644 --- a/frontend/appflowy_flutter/integration_test/share_markdown_test.dart +++ b/frontend/appflowy_flutter/integration_test/share_markdown_test.dart @@ -94,6 +94,13 @@ const expectedMarkdown = r''' 1. Keyboard shortcuts [guide](https://appflowy.gitbook.io/docs/essential-documentation/shortcuts) 1. Markdown [reference](https://appflowy.gitbook.io/docs/essential-documentation/markdown) 1. Type `/code` to insert a code block +```rust +// This is the main function. +fn main() { + // Print text to the console. + println!("Hello World!"); +} +``` ## Have a questionâť“ > Click `?` at the bottom right for help and support. diff --git a/frontend/appflowy_flutter/integration_test/util/editor_test_operations.dart b/frontend/appflowy_flutter/integration_test/util/editor_test_operations.dart index fcf4cd0d37..886b4a2b16 100644 --- a/frontend/appflowy_flutter/integration_test/util/editor_test_operations.dart +++ b/frontend/appflowy_flutter/integration_test/util/editor_test_operations.dart @@ -87,7 +87,7 @@ class EditorOperations { Future switchSolidColorBackground() async { final findPurpleButton = find.byWidgetPredicate( - (widget) => widget is ColorItem && widget.option.colorHex == "ffe8e0ff", + (widget) => widget is ColorItem && widget.option.name == 'Purple', ); await tester.tapButton(findPurpleButton); } diff --git a/frontend/appflowy_flutter/lib/plugins/document/application/editor_transaction_adapter.dart b/frontend/appflowy_flutter/lib/plugins/document/application/editor_transaction_adapter.dart index 79eb3aa7be..e1020fa53f 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/application/editor_transaction_adapter.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/application/editor_transaction_adapter.dart @@ -1,5 +1,6 @@ import 'package:appflowy/plugins/document/application/document_data_pb_extension.dart'; import 'package:appflowy/plugins/document/application/doc_service.dart'; +import 'package:appflowy_backend/log.dart'; import 'package:appflowy_backend/protobuf/flowy-document2/protobuf.dart'; import 'package:appflowy_editor/appflowy_editor.dart' show @@ -31,13 +32,13 @@ class TransactionAdapter { final String documentId; Future apply(Transaction transaction, EditorState editorState) async { - // Log.debug('transaction => ${transaction.toJson()}'); + Log.debug('transaction => ${transaction.toJson()}'); final actions = transaction.operations .map((op) => op.toBlockAction(editorState)) .whereNotNull() .expand((element) => element) .toList(growable: false); // avoid lazy evaluation - // Log.debug('actions => $actions'); + Log.debug('actions => $actions'); await documentService.applyAction( documentId: documentId, actions: actions, @@ -72,7 +73,7 @@ extension on InsertOperation { editorState.getNodeAtPath(path.previous)?.id ?? ''; assert(parentId.isNotEmpty); - if (path.equals(path.previous)) { + if (path.equals(path.previous) && !path.equals([0])) { prevId = ''; } else { assert(prevId.isNotEmpty && prevId != node.id); diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/callout/callout_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/callout/callout_block_component.dart index 9ee48c4e53..40837576a9 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/callout/callout_block_component.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/callout/callout_block_component.dart @@ -48,7 +48,7 @@ SelectionMenuItem calloutItem = SelectionMenuItem.node( name: 'Callout', iconData: Icons.note, keywords: ['callout'], - nodeBuilder: (editorState) => calloutNode(), + nodeBuilder: (editorState, _) => calloutNode(), replace: (_, node) => node.delta?.isEmpty ?? false, updateSelection: (_, path, __, ___) { return Selection.single(path: path, startOffset: 0); diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/code_block/code_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/code_block/code_block_component.dart index 5048ffc0c8..84eefc5738 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/code_block/code_block_component.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/code_block/code_block_component.dart @@ -43,7 +43,7 @@ SelectionMenuItem codeBlockItem = SelectionMenuItem.node( name: 'Code Block', iconData: Icons.abc, keywords: ['code', 'codeblock'], - nodeBuilder: (editorState) => codeBlockNode(), + nodeBuilder: (editorState, _) => codeBlockNode(), replace: (_, node) => node.delta?.isEmpty ?? false, ); diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/math_equation/math_equation_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/math_equation/math_equation_block_component.dart index b75eabb615..d4b93ee1d4 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/math_equation/math_equation_block_component.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/math_equation/math_equation_block_component.dart @@ -37,7 +37,7 @@ SelectionMenuItem mathEquationItem = SelectionMenuItem.node( name: 'MathEquation', iconData: Icons.text_fields_rounded, keywords: ['tex, latex, katex', 'math equation', 'formula'], - nodeBuilder: (editorState) => mathEquationNode(), + nodeBuilder: (editorState, _) => mathEquationNode(), replace: (_, node) => node.delta?.isEmpty ?? false, updateSelection: (editorState, path, __, ___) { WidgetsBinding.instance.addPostFrameCallback((timeStamp) { diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/openai/widgets/auto_completion_node_widget.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/openai/widgets/auto_completion_node_widget.dart index eb36767e80..e0d8355d6f 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/openai/widgets/auto_completion_node_widget.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/openai/widgets/auto_completion_node_widget.dart @@ -45,7 +45,7 @@ SelectionMenuItem autoGeneratorMenuItem = SelectionMenuItem.node( name: LocaleKeys.document_plugins_autoGeneratorMenuItemName.tr(), iconData: Icons.generating_tokens, keywords: ['ai', 'openai' 'writer', 'autogenerator'], - nodeBuilder: (editorState) { + nodeBuilder: (editorState, _) { final node = autoCompletionNode(start: editorState.selection!); return node; }, diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/outline/outline_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/outline/outline_block_component.dart index 5f9740b0a7..14ab936246 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/outline/outline_block_component.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/outline/outline_block_component.dart @@ -19,7 +19,7 @@ SelectionMenuItem outlineItem = SelectionMenuItem.node( name: LocaleKeys.document_selectionMenu_outline.tr(), iconData: Icons.list_alt, keywords: ['outline', 'table of contents'], - nodeBuilder: (editorState) => outlineBlockNode(), + nodeBuilder: (editorState, _) => outlineBlockNode(), replace: (_, node) => node.delta?.isEmpty ?? false, ); diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_component.dart index ad43d8264b..7ccf822641 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_component.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_component.dart @@ -49,7 +49,7 @@ SelectionMenuItem toggleListBlockItem = SelectionMenuItem.node( name: LocaleKeys.document_plugins_toggleList.tr(), iconData: Icons.arrow_right, keywords: ['collapsed list', 'toggle list', 'list'], - nodeBuilder: (editorState) => toggleListBlockNode(), + nodeBuilder: (editorState, _) => toggleListBlockNode(), replace: (_, node) => node.delta?.isEmpty ?? false, ); diff --git a/frontend/appflowy_flutter/pubspec.lock b/frontend/appflowy_flutter/pubspec.lock index 52dc094746..769a1718fb 100644 --- a/frontend/appflowy_flutter/pubspec.lock +++ b/frontend/appflowy_flutter/pubspec.lock @@ -53,10 +53,10 @@ packages: dependency: "direct main" description: name: appflowy_editor - sha256: b30f645eac57639ff003e6920d04432b9c80a4e2f6e177326e81c221608d7044 + sha256: "6886c32ab8c3f5385ec9eb333f3fca596fe5f5ee94da84484c7f56a322a026e7" url: "https://pub.dev" source: hosted - version: "1.2.1" + version: "1.2.3" appflowy_popover: dependency: "direct main" description: diff --git a/frontend/appflowy_flutter/pubspec.yaml b/frontend/appflowy_flutter/pubspec.yaml index 3bb4fcf78b..a0a067cdbf 100644 --- a/frontend/appflowy_flutter/pubspec.yaml +++ b/frontend/appflowy_flutter/pubspec.yaml @@ -42,7 +42,7 @@ dependencies: git: url: https://github.com/AppFlowy-IO/appflowy-board.git ref: a183c57 - appflowy_editor: ^1.2.1 + appflowy_editor: 1.2.3 appflowy_popover: path: packages/appflowy_popover