From 1166d03b7558d08ef9039c33f282b065fe801af5 Mon Sep 17 00:00:00 2001 From: "Lucas.Xu" Date: Wed, 3 Aug 2022 17:05:09 +0800 Subject: [PATCH] feat: update selection position after updating text node style. --- .../format_rich_text_style.dart | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/frontend/app_flowy/packages/flowy_editor/lib/service/default_text_operations/format_rich_text_style.dart b/frontend/app_flowy/packages/flowy_editor/lib/service/default_text_operations/format_rich_text_style.dart index 79e7bfe077..8e0e3e35b0 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/service/default_text_operations/format_rich_text_style.dart +++ b/frontend/app_flowy/packages/flowy_editor/lib/service/default_text_operations/format_rich_text_style.dart @@ -1,5 +1,7 @@ import 'package:flowy_editor/document/attributes.dart'; import 'package:flowy_editor/document/node.dart'; +import 'package:flowy_editor/document/position.dart'; +import 'package:flowy_editor/document/selection.dart'; import 'package:flowy_editor/editor_state.dart'; import 'package:flowy_editor/extensions/text_node_extensions.dart'; import 'package:flowy_editor/operation/transaction_builder.dart'; @@ -46,13 +48,20 @@ bool formatTextNodes(EditorState editorState, Attributes attributes) { final builder = TransactionBuilder(editorState); for (final textNode in textNodes) { - builder.updateNode( - textNode, - Attributes.fromIterable( - StyleKey.globalStyleKeys, - value: (_) => null, - )..addAll(attributes), - ); + builder + ..updateNode( + textNode, + Attributes.fromIterable( + StyleKey.globalStyleKeys, + value: (_) => null, + )..addAll(attributes), + ) + ..afterSelection = Selection.collapsed( + Position( + path: textNode.path, + offset: textNode.toRawString().length, + ), + ); } builder.commit();