Explorar el Código

feat: handle number list on delete event

Vincent Chan hace 2 años
padre
commit
ee0f3d3227

+ 0 - 1
frontend/app_flowy/packages/appflowy_editor/lib/src/operation/transaction_builder.dart

@@ -10,7 +10,6 @@ import 'package:appflowy_editor/src/document/text_delta.dart';
 import 'package:appflowy_editor/src/editor_state.dart';
 import 'package:appflowy_editor/src/operation/operation.dart';
 import 'package:appflowy_editor/src/operation/transaction.dart';
-import 'package:logging/logging.dart';
 
 /// A [TransactionBuilder] is used to build the transaction from the state.
 /// It will save a snapshot of the cursor selection state automatically.

+ 43 - 22
frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/backspace_handler.dart

@@ -181,30 +181,29 @@ KeyEventResult _handleDelete(EditorState editorState, RawKeyEvent event) {
   final transactionBuilder = TransactionBuilder(editorState);
   if (textNodes.length == 1) {
     final textNode = textNodes.first;
+    // The cursor is at the end of the line,
+    // merge next line into this line.
     if (selection.start.offset >= textNode.delta.length) {
-      final nextNode = textNode.next;
-      if (nextNode == null) {
-        return KeyEventResult.ignored;
-      }
-      if (nextNode is TextNode) {
-        transactionBuilder.mergeText(textNode, nextNode);
-      }
-      transactionBuilder.deleteNode(nextNode);
+      return _mergeNextLineIntoThisLine(
+        editorState,
+        textNode,
+        transactionBuilder,
+        selection,
+      );
+    }
+    final index = textNode.delta.nextRunePosition(selection.start.offset);
+    if (selection.isCollapsed) {
+      transactionBuilder.deleteText(
+        textNode,
+        selection.start.offset,
+        index - selection.start.offset,
+      );
     } else {
-      final index = textNode.delta.nextRunePosition(selection.start.offset);
-      if (selection.isCollapsed) {
-        transactionBuilder.deleteText(
-          textNode,
-          selection.start.offset,
-          index - selection.start.offset,
-        );
-      } else {
-        transactionBuilder.deleteText(
-          textNode,
-          selection.start.offset,
-          selection.end.offset - selection.start.offset,
-        );
-      }
+      transactionBuilder.deleteText(
+        textNode,
+        selection.start.offset,
+        selection.end.offset - selection.start.offset,
+      );
     }
     transactionBuilder.commit();
   } else {
@@ -222,6 +221,28 @@ KeyEventResult _handleDelete(EditorState editorState, RawKeyEvent event) {
   return KeyEventResult.handled;
 }
 
+KeyEventResult _mergeNextLineIntoThisLine(
+    EditorState editorState,
+    TextNode textNode,
+    TransactionBuilder transactionBuilder,
+    Selection selection) {
+  final nextNode = textNode.next;
+  if (nextNode == null) {
+    return KeyEventResult.ignored;
+  }
+  if (nextNode is TextNode) {
+    transactionBuilder.mergeText(textNode, nextNode);
+  }
+  transactionBuilder.deleteNode(nextNode);
+  transactionBuilder.commit();
+
+  if (textNode.subtype == StyleKey.numberList) {
+    makeFollowingNodesIncremental(editorState, textNode.path, selection);
+  }
+
+  return KeyEventResult.handled;
+}
+
 void _deleteTextNodes(TransactionBuilder transactionBuilder,
     List<TextNode> textNodes, Selection selection) {
   final first = textNodes.first;