浏览代码

feat: check previous node's number

Vincent Chan 2 年之前
父节点
当前提交
875c109b14

+ 16 - 0
frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/whitespace_handler.dart

@@ -77,6 +77,22 @@ KeyEventResult _toNumberList(EditorState editorState, TextNode textNode,
     return KeyEventResult.ignored;
   }
 
+  // The user types number + . + space, he wants to turn
+  // this line into number list, but we should check if previous line
+  // is number list.
+  //
+  // Check whether the number input by the user is the successor of the previous
+  // line. If it's not, ignore it.
+  final prevNode = textNode.previous;
+  if (prevNode != null &&
+      prevNode is TextNode &&
+      prevNode.attributes[StyleKey.subtype] == StyleKey.numberList) {
+    final prevNumber = prevNode.attributes[StyleKey.number] as int;
+    if (numValue != prevNumber + 1) {
+      return KeyEventResult.ignored;
+    }
+  }
+
   final afterSelection = Selection.collapsed(Position(
     path: textNode.path,
     offset: 0,