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,12 +48,19 @@ 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
..updateNode(
textNode, textNode,
Attributes.fromIterable( Attributes.fromIterable(
StyleKey.globalStyleKeys, StyleKey.globalStyleKeys,
value: (_) => null, value: (_) => null,
)..addAll(attributes), )..addAll(attributes),
)
..afterSelection = Selection.collapsed(
Position(
path: textNode.path,
offset: textNode.toRawString().length,
),
); );
} }