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.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
fix: fix something wrong when deleting the text nodes
Lucas.Xu585c9f87535e
diff --git a/frontend/app_flowy/packages/flowy_editor/lib/document/node.dart b/frontend/app_flowy/packages/flowy_editor/lib/document/node.dartindex c3f75c5c9c..21883362b1 100644--- a/frontend/app_flowy/packages/flowy_editor/lib/document/node.dart+++ b/frontend/app_flowy/packages/flowy_editor/lib/document/node.dart@@ -183,7 +183,7 @@ class TextNode extends Node {super(children: children ?? LinkedList(), attributes: attributes ?? {});TextNode.empty()- : _delta = Delta([TextInsert(' ')]),+ : _delta = Delta([TextInsert('')]),super(type: 'text',children: LinkedList(),diff --git a/frontend/app_flowy/packages/flowy_editor/lib/service/internal_key_event_handlers/delete_text_handler.dart b/frontend/app_flowy/packages/flowy_editor/lib/service/internal_key_event_handlers/delete_text_handler.dartindex 861449c0ab..e44f0002a0 100644--- a/frontend/app_flowy/packages/flowy_editor/lib/service/internal_key_event_handlers/delete_text_handler.dart+++ b/frontend/app_flowy/packages/flowy_editor/lib/service/internal_key_event_handlers/delete_text_handler.dart@@ -46,8 +46,14 @@ FlowyKeyEventHandler deleteTextHandler = (editorState, event) {if (textNode.previous is TextNode) {final previous = textNode.previous as TextNode;transactionBuilder+ ..mergeText(previous, textNode)..deleteNode(textNode)- ..mergeText(previous, textNode);+ ..afterSelection = Selection.collapsed(+ Position(+ path: previous.path,+ offset: previous.toRawString().length,+ ),+ );break;}}diff --git a/frontend/app_flowy/packages/flowy_editor/lib/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler.dart b/frontend/app_flowy/packages/flowy_editor/lib/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler.dartindex 8a53c1e9f4..cf71830386 100644--- a/frontend/app_flowy/packages/flowy_editor/lib/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler.dart+++ b/frontend/app_flowy/packages/flowy_editor/lib/service/internal_key_event_handlers/enter_without_shift_in_text_node_handler.dart@@ -17,7 +17,8 @@ import 'package:flowy_editor/service/keyboard_service.dart';/// 2. Single selection and the selected node is [TextNode]/// 2.1 split the node into two nodes with style/// 2.2 or insert a empty text node before.-FlowyKeyEventHandler enterWithoutShiftHandler = (editorState, event) {+FlowyKeyEventHandler enterWithoutShiftInTextNodesHandler =+ (editorState, event) {if (event.logicalKey != LogicalKeyboardKey.enter || event.isShiftPressed) {return KeyEventResult.ignored;}@@ -87,11 +88,6 @@ FlowyKeyEventHandler enterWithoutShiftHandler = (editorState, event) {Position(path: textNode.path.next, offset: 0),);TransactionBuilder(editorState)- ..deleteText(- textNode,- selection.start.offset,- textNode.toRawString().length,- )..insertNode(textNode.path.next,textNode.copyWith(@@ -99,6 +95,11 @@ FlowyKeyEventHandler enterWithoutShiftHandler = (editorState, event) {delta: textNode.delta.slice(selection.end.offset),),)+ ..deleteText(+ textNode,+ selection.start.offset,+ textNode.toRawString().length - selection.start.offset,+ )..afterSelection = afterSelection..commit();return KeyEventResult.handled;