feat: update selection position after updating text node style.

This commit is contained in:
Lucas.Xu 2022-08-03 17:05:09 +08:00
parent 35bafbaadc
commit 1166d03b75

View File

@ -1,5 +1,7 @@
import 'package:flowy_editor/document/attributes.dart'; import 'package:flowy_editor/document/attributes.dart';
import 'package:flowy_editor/document/node.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/editor_state.dart';
import 'package:flowy_editor/extensions/text_node_extensions.dart'; import 'package:flowy_editor/extensions/text_node_extensions.dart';
import 'package:flowy_editor/operation/transaction_builder.dart'; import 'package:flowy_editor/operation/transaction_builder.dart';
@ -46,13 +48,20 @@ bool formatTextNodes(EditorState editorState, Attributes attributes) {
final builder = TransactionBuilder(editorState); final builder = TransactionBuilder(editorState);
for (final textNode in textNodes) { for (final textNode in textNodes) {
builder.updateNode( builder
textNode, ..updateNode(
Attributes.fromIterable( textNode,
StyleKey.globalStyleKeys, Attributes.fromIterable(
value: (_) => null, StyleKey.globalStyleKeys,
)..addAll(attributes), value: (_) => null,
); )..addAll(attributes),
)
..afterSelection = Selection.collapsed(
Position(
path: textNode.path,
offset: textNode.toRawString().length,
),
);
} }
builder.commit(); builder.commit();