chore: fix test error

This commit is contained in:
Lucas.Xu 2022-08-02 16:25:35 +08:00
parent 56ac86fb51
commit fa05170c86
3 changed files with 18 additions and 7 deletions

View File

@ -30,14 +30,10 @@ class TransactionBuilder {
insertNode(Path path, Node node) {
insertNodes(path, [node]);
// FIXME: Not exactly correct, needs to be customized.
afterSelection = Selection.collapsed(
Position(path: path, offset: 0),
);
}
insertNodes(Path path, List<Node> nodes) {
beforeSelection = state.service.selectionService.currentSelection;
beforeSelection = state.cursorSelection;
add(InsertOperation(path, nodes));
}
@ -74,7 +70,7 @@ class TransactionBuilder {
}
textEdit(TextNode node, Delta Function() f) {
beforeSelection = state.service.selectionService.currentSelection;
beforeSelection = state.cursorSelection;
final path = node.path;
final delta = f();

View File

@ -4,6 +4,8 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.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/document/text_delta.dart';
import 'package:flowy_editor/extensions/node_extensions.dart';
import 'package:flowy_editor/extensions/path_extensions.dart';
@ -40,6 +42,12 @@ FlowyKeyEventHandler enterInEdgeOfTextNodeHandler = (editorState, event) {
needCopyAttributes ? {StyleKey.subtype: textNode.subtype} : {},
),
)
..afterSelection = Selection.collapsed(
Position(
path: textNode.path.next,
offset: 0,
),
)
..commit();
return KeyEventResult.handled;
} else if (textNode.selectable!.start() == selection.start) {
@ -52,6 +60,12 @@ FlowyKeyEventHandler enterInEdgeOfTextNodeHandler = (editorState, event) {
attributes: {},
),
)
..afterSelection = Selection.collapsed(
Position(
path: textNode.path.next,
offset: 0,
),
)
..commit();
return KeyEventResult.handled;
}

View File

@ -8,6 +8,7 @@ import 'package:flowy_editor/editor_state.dart';
import 'package:flowy_editor/document/state_tree.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
group('transform path', () {
test('transform path changed', () {
expect(transformPath([0, 1], [0, 1]), [0, 2]);
@ -87,7 +88,7 @@ void main() {
"path": [0],
"nodes": [item1.toJson()],
}
],
]
});
});
test("delete", () {