Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

fix: cancel number list style after enter in empty line

Vincent Chan06bd6064ac37
diff --git a/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler.dart
index e6cb91d318..4ed21f21f8 100644
--- a/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler.dart
+++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler.dart
@@ -76,9 +76,7 @@ ShortcutEventHandler enterWithoutShiftInTextNodesHandler =
// If selection is collapsed and position.start.offset == 0,
// insert a empty text node before.
- if (selection.isCollapsed &&
- selection.start.offset == 0 &&
- textNode.subtype != StyleKey.numberList) {
+ if (selection.isCollapsed && selection.start.offset == 0) {
if (textNode.toRawString().isEmpty && textNode.subtype != null) {
final afterSelection = Selection.collapsed(
Position(path: textNode.path, offset: 0),
@@ -92,17 +90,44 @@ ShortcutEventHandler enterWithoutShiftInTextNodesHandler =
))
..afterSelection = afterSelection
..commit();
+
+ final nextNode = textNode.next;
+ if (nextNode is TextNode && nextNode.subtype == StyleKey.numberList) {
+ makeFollowingNodesIncremental(
+ editorState, textNode.path, afterSelection,
+ beginNum: 0);
+ }
} else {
+ final subtype = textNode.subtype;
final afterSelection = Selection.collapsed(
Position(path: textNode.path.next, offset: 0),
);
- TransactionBuilder(editorState)
- ..insertNode(
- textNode.path,
- TextNode.empty(),
- )
- ..afterSelection = afterSelection
- ..commit();
+
+ if (subtype == StyleKey.numberList) {
+ final prevNumber = textNode.attributes[StyleKey.number] as int;
+ final newNode = TextNode.empty();
+ newNode.attributes[StyleKey.subtype] = StyleKey.numberList;
+ newNode.attributes[StyleKey.number] = prevNumber;
+ final insertPath = textNode.path;
+ TransactionBuilder(editorState)
+ ..insertNode(
+ insertPath,
+ newNode,
+ )
+ ..afterSelection = afterSelection
+ ..commit();
+
+ makeFollowingNodesIncremental(editorState, insertPath, afterSelection,
+ beginNum: prevNumber);
+ } else {
+ TransactionBuilder(editorState)
+ ..insertNode(
+ textNode.path,
+ TextNode.empty(),
+ )
+ ..afterSelection = afterSelection
+ ..commit();
+ }
}
return KeyEventResult.handled;
}
diff --git a/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler_test.dart
index 7307f9cf2f..5bfe1ada67 100644
--- a/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler_test.dart
+++ b/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler_test.dart
@@ -176,15 +176,8 @@ Future<void> _testStyleNeedToBeCopy(WidgetTester tester, String style) async {
await editor.pressLogicKey(
LogicalKeyboardKey.enter,
);
- if (style == StyleKey.numberList) {
- expect(
- editor.documentSelection, Selection.single(path: [5], startOffset: 0));
- expect(editor.nodeAtPath([4])?.subtype, StyleKey.numberList);
- } else {
- expect(
- editor.documentSelection, Selection.single(path: [4], startOffset: 0));
- expect(editor.nodeAtPath([4])?.subtype, null);
- }
+ expect(editor.documentSelection, Selection.single(path: [4], startOffset: 0));
+ expect(editor.nodeAtPath([4])?.subtype, null);
}
Future<void> _testMultipleSelection(