Browse Source

chore: update editor version to 1.2.3 (#3153)

Lucas.Xu 1 năm trước cách đây
mục cha
commit
c9ee82ec75

+ 47 - 0
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',
+        );
+      }
+    });
+  });
+}

+ 2 - 0
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();
 }

+ 7 - 0
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.

+ 1 - 1
frontend/appflowy_flutter/integration_test/util/editor_test_operations.dart

@@ -87,7 +87,7 @@ class EditorOperations {
 
   Future<void> 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);
   }

+ 4 - 3
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<void> 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);

+ 1 - 1
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);

+ 1 - 1
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,
 );
 

+ 1 - 1
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) {

+ 1 - 1
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;
   },

+ 1 - 1
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,
 );
 

+ 1 - 1
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,
 );
 

+ 2 - 2
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:

+ 1 - 1
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