Ver código fonte

fix: pressing enter key in the edge of node doesn't work good.

Lucas.Xu 2 anos atrás
pai
commit
a1be60721e

+ 10 - 7
frontend/app_flowy/packages/flowy_editor/example/lib/main.dart

@@ -116,13 +116,16 @@ class _MyHomePageState extends State<MyHomePage> {
           _editorState = EditorState(
             document: document,
           );
-          return FlowyEditor(
-            key: editorKey,
-            editorState: _editorState,
-            keyEventHandlers: const [],
-            customBuilders: {
-              'image': ImageNodeBuilder(),
-            },
+          return Container(
+            padding: const EdgeInsets.only(left: 20, right: 20),
+            child: FlowyEditor(
+              key: editorKey,
+              editorState: _editorState,
+              keyEventHandlers: const [],
+              customBuilders: {
+                'image': ImageNodeBuilder(),
+              },
+            ),
             // shortcuts: [
             //   // TODO: this won't work, just a example for now.
             //   {

+ 1 - 1
frontend/app_flowy/packages/flowy_editor/lib/render/rich_text/flowy_rich_text.dart

@@ -74,7 +74,7 @@ class _FlowyRichTextState extends State<FlowyRichText> with Selectable {
         _renderParagraph.getOffsetForCaret(textPosition, Rect.zero);
     final cursorHeight = widget.cursorHeight ??
         _renderParagraph.getFullHeightForCaret(textPosition) ??
-        5.0; // default height
+        18.0; // default height
     return Rect.fromLTWH(
       cursorOffset.dx - (widget.cursorWidth / 2),
       cursorOffset.dy,

+ 1 - 0
frontend/app_flowy/packages/flowy_editor/lib/render/rich_text/rich_text_style.dart

@@ -51,6 +51,7 @@ class StyleKey {
 
   static List<String> globalStyleKeys = [
     StyleKey.heading,
+    StyleKey.checkbox,
     StyleKey.bulletedList,
     StyleKey.numberList,
     StyleKey.quote,

+ 3 - 4
frontend/app_flowy/packages/flowy_editor/lib/service/internal_key_event_handlers/enter_in_edge_of_text_node_handler.dart

@@ -37,9 +37,8 @@ FlowyKeyEventHandler enterInEdgeOfTextNodeHandler = (editorState, event) {
         textNode.path.next,
         textNode.copyWith(
           children: LinkedList(),
-          delta: Delta([TextInsert(' ')]),
-          attributes:
-              needCopyAttributes ? {StyleKey.subtype: textNode.subtype} : {},
+          delta: Delta([TextInsert('')]),
+          attributes: needCopyAttributes ? textNode.attributes : {},
         ),
       )
       ..afterSelection = Selection.collapsed(
@@ -56,7 +55,7 @@ FlowyKeyEventHandler enterInEdgeOfTextNodeHandler = (editorState, event) {
         textNode.path,
         textNode.copyWith(
           children: LinkedList(),
-          delta: Delta([TextInsert(' ')]),
+          delta: Delta([TextInsert('')]),
           attributes: {},
         ),
       )

+ 5 - 2
frontend/app_flowy/packages/flowy_editor/lib/service/selection_service.dart

@@ -233,6 +233,9 @@ class _FlowySelectionState extends State<FlowySelection>
 
   @override
   void dispose() {
+    clearSelection();
+    WidgetsBinding.instance.removeObserver(this);
+
     super.dispose();
   }
 
@@ -455,7 +458,7 @@ class _FlowySelectionState extends State<FlowySelection>
       ..forEach((overlay) => overlay.remove())
       ..clear();
     // clear toolbar
-    editorState.service.toolbarService.hide();
+    editorState.service.toolbarService?.hide();
   }
 
   void _updateSelection(Selection selection) {
@@ -526,7 +529,7 @@ class _FlowySelectionState extends State<FlowySelection>
 
     if (topmostRect != null && layerLink != null) {
       editorState.service.toolbarService
-          .showInOffset(topmostRect.topLeft, layerLink);
+          ?.showInOffset(topmostRect.topLeft, layerLink);
     }
   }
 

+ 6 - 4
frontend/app_flowy/packages/flowy_editor/lib/service/service.dart

@@ -23,9 +23,11 @@ class FlowyService {
 
   // toolbar service
   final toolbarServiceKey = GlobalKey(debugLabel: 'flowy_toolbar_service');
-  ToolbarService get toolbarService {
-    assert(toolbarServiceKey.currentState != null &&
-        toolbarServiceKey.currentState is ToolbarService);
-    return toolbarServiceKey.currentState! as ToolbarService;
+  ToolbarService? get toolbarService {
+    if (toolbarServiceKey.currentState != null &&
+        toolbarServiceKey.currentState is ToolbarService) {
+      return toolbarServiceKey.currentState! as ToolbarService;
+    }
+    return null;
   }
 }