Browse Source

fix: #1763 [Bug] Mouse unable to click a certain area

Lucas.Xu 2 years ago
parent
commit
fb30989cf8

+ 0 - 1
frontend/app_flowy/packages/appflowy_editor/example/assets/example.json

@@ -23,7 +23,6 @@
         ]
       },
       { "type": "text", "delta": [] },
-      { "type": "board" },
       {
         "type": "text",
         "delta": [

+ 1 - 0
frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler.dart

@@ -80,6 +80,7 @@ ShortcutEventHandler enterWithoutShiftInTextNodesHandler =
       final transaction = editorState.transaction
         ..updateNode(textNode, {
           BuiltInAttributeKey.subtype: null,
+          textNode.subtype!: null,
         })
         ..afterSelection = afterSelection;
       editorState.apply(transaction);

+ 6 - 1
frontend/app_flowy/packages/appflowy_editor/lib/src/service/render_plugin_service.dart

@@ -77,7 +77,12 @@ class AppFlowyRenderPlugin extends AppFlowyRenderPluginService {
       return _autoUpdateNodeWidget(builder, context);
     } else {
       // Returns a SizeBox with 0 height if no builder found.
-      return const SizedBox(
+      assert(
+        false,
+        'No builder found for node(${node.id}, attributes(${node.attributes})})',
+      );
+      return SizedBox(
+        key: node.key,
         height: 0,
       );
     }

+ 57 - 0
frontend/app_flowy/packages/appflowy_editor/test/render/rich_text/checkbox_text_test.dart

@@ -1,5 +1,6 @@
 import 'package:appflowy_editor/appflowy_editor.dart';
 import 'package:appflowy_editor/src/extensions/text_node_extensions.dart';
+import 'package:flutter/services.dart';
 import 'package:flutter_test/flutter_test.dart';
 import '../../infra/test_editor.dart';
 
@@ -67,5 +68,61 @@ void main() async {
       expect(node.allSatisfyUnderlineInSelection(selection), true);
       expect(node.allSatisfyStrikethroughInSelection(selection), true);
     });
+
+    // https://github.com/AppFlowy-IO/AppFlowy/issues/1763
+    // [Bug] Mouse unable to click a certain area #1763
+    testWidgets('insert a new checkbox after an exsiting checkbox',
+        (tester) async {
+      // Before
+      //
+      // [checkbox] Welcome to Appflowy 😁
+      //
+      // After
+      //
+      // [checkbox] Welcome to Appflowy 😁
+      //
+      // [checkbox] Welcome to Appflowy 😁
+      //
+      const text = 'Welcome to Appflowy 😁';
+      final editor = tester.editor
+        ..insertTextNode(
+          '',
+          attributes: {
+            BuiltInAttributeKey.subtype: BuiltInAttributeKey.checkbox,
+            BuiltInAttributeKey.checkbox: false,
+          },
+          delta: Delta(
+            operations: [TextInsert(text)],
+          ),
+        );
+      await editor.startTesting();
+      await editor.updateSelection(
+        Selection.single(path: [0], startOffset: text.length),
+      );
+
+      await editor.pressLogicKey(LogicalKeyboardKey.enter);
+      await editor.pressLogicKey(LogicalKeyboardKey.enter);
+      await editor.pressLogicKey(LogicalKeyboardKey.enter);
+
+      expect(
+        editor.documentSelection,
+        Selection.single(path: [2], startOffset: 0),
+      );
+
+      await editor.pressLogicKey(LogicalKeyboardKey.slash);
+      await tester.pumpAndSettle(const Duration(milliseconds: 1000));
+
+      expect(
+        find.byType(SelectionMenuWidget, skipOffstage: false),
+        findsOneWidget,
+      );
+
+      final checkboxMenuItem = find.text('Checkbox', findRichText: true);
+      await tester.tap(checkboxMenuItem);
+      await tester.pumpAndSettle();
+
+      final checkboxNode = editor.nodeAtPath([2]) as TextNode;
+      expect(checkboxNode.subtype, BuiltInAttributeKey.checkbox);
+    });
   });
 }