fix: Should not add a new line below after pressing enter at the front of the first line of text.

This commit is contained in:
Lucas.Xu 2022-08-29 11:40:34 +08:00
parent cde48926e2
commit c07af9007c
2 changed files with 32 additions and 4 deletions

View File

@ -62,10 +62,17 @@ class StateTree {
}
return false;
}
for (var i = 0; i < nodes.length; i++) {
final node = nodes[i];
insertedNode!.insertAfter(node);
insertedNode = node;
if (path.last <= 0) {
for (var i = 0; i < nodes.length; i++) {
final node = nodes[i];
insertedNode.insertBefore(node);
}
} else {
for (var i = 0; i < nodes.length; i++) {
final node = nodes[i];
insertedNode!.insertAfter(node);
insertedNode = node;
}
}
return true;
}

View File

@ -116,6 +116,27 @@ void main() async {
(tester) async {
_testMultipleSelection(tester, false);
});
testWidgets('Presses enter key in the first line', (tester) async {
// Before
//
// Welcome to Appflowy 😁
//
// After
//
// [Empty Line]
// Welcome to Appflowy 😁
//
const text = 'Welcome to Appflowy 😁';
final editor = tester.editor..insertTextNode(text);
await editor.startTesting();
await editor.updateSelection(
Selection.single(path: [0], startOffset: 0),
);
await editor.pressLogicKey(LogicalKeyboardKey.enter);
expect(editor.documentLength, 2);
expect((editor.nodeAtPath([1]) as TextNode).toRawString(), text);
});
});
}