Vincent Chan 2 rokov pred
rodič
commit
2810097b95

+ 11 - 0
frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/backspace_handler.dart

@@ -1,4 +1,5 @@
 import 'package:appflowy_editor/src/render/rich_text/rich_text_style.dart';
+import 'package:appflowy_editor/src/service/internal_key_event_handlers/number_list_helper.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter/services.dart';
 
@@ -29,6 +30,7 @@ KeyEventResult _handleBackspace(EditorState editorState, RawKeyEvent event) {
       nodes.where((node) => node is! TextNode).toList(growable: false);
 
   final transactionBuilder = TransactionBuilder(editorState);
+  List<int>? cancelNumberListPath;
 
   if (nonTextNodes.isNotEmpty) {
     transactionBuilder.deleteNodes(nonTextNodes);
@@ -40,6 +42,9 @@ KeyEventResult _handleBackspace(EditorState editorState, RawKeyEvent event) {
     if (index < 0 && selection.isCollapsed) {
       // 1. style
       if (textNode.subtype != null) {
+        if (textNode.subtype == StyleKey.numberList) {
+          cancelNumberListPath = textNode.path;
+        }
         transactionBuilder
           ..updateNode(textNode, {
             StyleKey.subtype: null,
@@ -100,6 +105,12 @@ KeyEventResult _handleBackspace(EditorState editorState, RawKeyEvent event) {
     transactionBuilder.commit();
   }
 
+  if (cancelNumberListPath != null) {
+    makeFollowingNodesIncremental(
+        editorState, cancelNumberListPath, Selection.collapsed(selection.start),
+        beginNum: 0);
+  }
+
   return KeyEventResult.handled;
 }
 

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

@@ -69,7 +69,9 @@ ShortcutEventHandler enterWithoutShiftInTextNodesHandler =
 
   // If selection is collapsed and position.start.offset == 0,
   //  insert a empty text node before.
-  if (selection.isCollapsed && selection.start.offset == 0) {
+  if (selection.isCollapsed &&
+      selection.start.offset == 0 &&
+      textNode.subtype != StyleKey.numberList) {
     if (textNode.toRawString().isEmpty && textNode.subtype != null) {
       final afterSelection = Selection.collapsed(
         Position(path: textNode.path, offset: 0),

+ 3 - 2
frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/number_list_helper.dart

@@ -5,12 +5,13 @@ import 'package:appflowy_editor/src/operation/transaction_builder.dart';
 import 'package:appflowy_editor/src/document/attributes.dart';
 
 void makeFollowingNodesIncremental(
-    EditorState editorState, List<int> insertPath, Selection afterSelection) {
+    EditorState editorState, List<int> insertPath, Selection afterSelection,
+    {int? beginNum}) {
   final insertNode = editorState.document.nodeAtPath(insertPath);
   if (insertNode == null) {
     return;
   }
-  final int beginNum = insertNode.attributes[StyleKey.number] as int;
+  beginNum ??= insertNode.attributes[StyleKey.number] as int;
 
   int numPtr = beginNum + 1;
   var ptr = insertNode.next;