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.

feat: handle number list on delete event

Vincent Chanee0f3d322726
diff --git a/frontend/app_flowy/packages/appflowy_editor/lib/src/operation/transaction_builder.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/operation/transaction_builder.dart
index 41be1c8c48..c990a3921f 100644
--- a/frontend/app_flowy/packages/appflowy_editor/lib/src/operation/transaction_builder.dart
+++ b/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.
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 5b391aea41..82d7f7f3b3 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
@@ -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;