From 27757372607d86649f93864173a1028ba67b21cd Mon Sep 17 00:00:00 2001 From: Vincent Chan Date: Fri, 9 Sep 2022 15:13:21 +0800 Subject: [PATCH] feat: refresh number list when delete multiple lines --- .../backspace_handler.dart | 25 ++++++++++++++++--- ...er_without_shift_in_text_node_handler.dart | 7 ++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/backspace_handler.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/backspace_handler.dart index a8337543e7..1e252d9114 100644 --- a/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/backspace_handler.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/backspace_handler.dart @@ -93,9 +93,19 @@ KeyEventResult _handleBackspace(EditorState editorState, RawKeyEvent event) { } } } else { - if (textNodes.isNotEmpty) { - _deleteTextNodes(transactionBuilder, textNodes, selection); + if (textNodes.isEmpty) { + return KeyEventResult.handled; } + final startPosition = selection.start; + final nodeAtStart = editorState.document.nodeAtPath(startPosition.path)!; + _deleteTextNodes(transactionBuilder, textNodes, selection); + transactionBuilder.commit(); + + if (nodeAtStart is TextNode && nodeAtStart.subtype == StyleKey.numberList) { + makeFollowingNodesIncremental( + editorState, startPosition.path, transactionBuilder.afterSelection!); + } + return KeyEventResult.handled; } if (transactionBuilder.operations.isNotEmpty) { @@ -156,11 +166,18 @@ KeyEventResult _handleDelete(EditorState editorState, RawKeyEvent event) { ); } } + transactionBuilder.commit(); } else { + final startPosition = selection.start; + final nodeAtStart = editorState.document.nodeAtPath(startPosition.path)!; _deleteTextNodes(transactionBuilder, textNodes, selection); - } + transactionBuilder.commit(); - transactionBuilder.commit(); + if (nodeAtStart is TextNode && nodeAtStart.subtype == StyleKey.numberList) { + makeFollowingNodesIncremental( + editorState, startPosition.path, transactionBuilder.afterSelection!); + } + } return KeyEventResult.handled; } 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 0a8ee552cb..e6cb91d318 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 @@ -37,6 +37,7 @@ ShortcutEventHandler enterWithoutShiftInTextNodesHandler = // Multiple selection if (!selection.isSingle) { + final startNode = editorState.document.nodeAtPath(selection.start.path)!; final length = textNodes.length; final List subTextNodes = length >= 3 ? textNodes.sublist(1, textNodes.length - 1) : []; @@ -57,6 +58,12 @@ ShortcutEventHandler enterWithoutShiftInTextNodesHandler = ) ..afterSelection = afterSelection ..commit(); + + if (startNode is TextNode && startNode.subtype == StyleKey.numberList) { + makeFollowingNodesIncremental( + editorState, selection.start.path, afterSelection); + } + return KeyEventResult.handled; }