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: could not remove text style when pressing enter in empty text node
Lucas.Xu1391d202a971
diff --git a/frontend/app_flowy/packages/flowy_editor/lib/operation/transaction_builder.dart b/frontend/app_flowy/packages/flowy_editor/lib/operation/transaction_builder.dartindex 55ca336bfb..2898f7113a 100644--- a/frontend/app_flowy/packages/flowy_editor/lib/operation/transaction_builder.dart+++ b/frontend/app_flowy/packages/flowy_editor/lib/operation/transaction_builder.dart@@ -137,17 +137,16 @@ class TransactionBuilder {replaceText(TextNode node, int index, int length, String content,[Attributes? attributes]) {+ var newAttributes = attributes;+ if (attributes == null) {+ final ops = node.delta.slice(index, index + length).operations;+ if (ops.isNotEmpty) {+ newAttributes = ops.first.attributes;+ }+ }textEdit(node,- () => Delta().retain(index).delete(length).insert(- content,- attributes ??- node.delta- .slice(index, index + length)- .operations- .first- .attributes,- ),+ () => Delta().retain(index).delete(length).insert(content, newAttributes),);afterSelection = Selection.collapsed(Position(diff --git a/frontend/app_flowy/packages/flowy_editor/lib/render/rich_text/rich_text_style.dart b/frontend/app_flowy/packages/flowy_editor/lib/render/rich_text/rich_text_style.dartindex e39aed9aa2..c44fd8dac1 100644--- a/frontend/app_flowy/packages/flowy_editor/lib/render/rich_text/rich_text_style.dart+++ b/frontend/app_flowy/packages/flowy_editor/lib/render/rich_text/rich_text_style.dart@@ -51,6 +51,7 @@ class StyleKey {];static List<String> globalStyleKeys = [+ StyleKey.subtype,StyleKey.heading,StyleKey.checkbox,StyleKey.bulletedList,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 d2d3b14450..3dd0eef2df 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@@ -67,16 +67,31 @@ FlowyKeyEventHandler enterWithoutShiftInTextNodesHandler =// If selection is collapsed and position.start.offset == 0,// insert a empty text node before.if (selection.isCollapsed && selection.start.offset == 0) {- final afterSelection = Selection.collapsed(- Position(path: textNode.path.next, offset: 0),- );- TransactionBuilder(editorState)- ..insertNode(- textNode.path,- TextNode.empty(),- )- ..afterSelection = afterSelection- ..commit();+ if (textNode.toRawString().isEmpty) {+ final afterSelection = Selection.collapsed(+ Position(path: textNode.path, offset: 0),+ );+ TransactionBuilder(editorState)+ ..updateNode(+ textNode,+ Attributes.fromIterable(+ StyleKey.globalStyleKeys,+ value: (_) => null,+ ))+ ..afterSelection = afterSelection+ ..commit();+ } else {+ final afterSelection = Selection.collapsed(+ Position(path: textNode.path.next, offset: 0),+ );+ TransactionBuilder(editorState)+ ..insertNode(+ textNode.path,+ TextNode.empty(),+ )+ ..afterSelection = afterSelection+ ..commit();+ }return KeyEventResult.handled;}