Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed the cursor not moving to next line after inserting divider #371

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Future<bool> _convertSyntaxToDivider(
..insertNode(path, dividerNode())
..insertNode(path, paragraphNode())
..deleteNode(node)
..afterSelection = Selection.collapsed(Position(path: path));
..afterSelection = Selection.collapsed(Position(path: path.next));
editorState.apply(transaction);
return true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void main() async {
formatAsteriskToBulletedList,
'*',
1,
(result, before, after) {
(result, before, after, editorState) {
expect(result, true);
expect(after.delta!.toPlainText(), text);
expect(after.type, 'bulleted_list');
Expand All @@ -36,7 +36,7 @@ void main() async {
formatAsteriskToBulletedList,
'*',
2,
(result, before, after) {
(result, before, after, editorState) {
// nothing happens
expect(result, false);
expect(before.toJson(), after.toJson());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ void main() async {
convertMinusesToDivider,
'--',
2,
(result, before, after) {
(result, before, after, editorState) {
expect(result, true);
expect(after.delta, null);
expect(after.type, DividerBlockKeys.type);
expect(after.next, isNotNull);
expect(after.next!.type, ParagraphBlockKeys.type);
final nextNode = editorState.getNodeAtPath(after.next!.path);
expect(nextNode!.path, editorState.selection!.end.path);
},
text: text,
);
Expand All @@ -36,7 +40,7 @@ void main() async {
convertStarsToDivider,
'**',
2,
(result, before, after) {
(result, before, after, editorState) {
expect(result, true);
expect(after.delta, null);
expect(after.type, DividerBlockKeys.type);
Expand All @@ -55,7 +59,7 @@ void main() async {
convertUnderscoreToDivider,
'__',
2,
(result, before, after) {
(result, before, after, editorState) {
expect(result, true);
expect(after.delta, null);
expect(after.type, DividerBlockKeys.type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void main() async {
formatSignToHeading,
'',
0,
(result, before, after) {
(result, before, after, editorState) {
expect(result, false);
expect(before.delta!.toPlainText(), '');
expect(after.delta!.toPlainText(), '');
Expand All @@ -37,7 +37,7 @@ void main() async {
formatSignToHeading,
'#' * i,
i,
(result, before, after) {
(result, before, after, editorState) {
expect(result, true);
expect(after.delta!.toPlainText(), text);
expect(after.type, 'heading');
Expand All @@ -56,7 +56,7 @@ void main() async {
formatSignToHeading,
'#' * 7,
7,
(result, before, after) {
(result, before, after, editorState) {
// nothing happens
expect(result, false);
expect(before.toJson(), after.toJson());
Expand All @@ -74,7 +74,7 @@ void main() async {
formatSignToHeading,
'#',
2,
(result, before, after) {
(result, before, after, editorState) {
// nothing happens
expect(result, false);
expect(before.toJson(), after.toJson());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void main() async {
formatNumberToNumberedList,
'1',
1,
(result, before, after) {
(result, before, after, editorState) {
// nothing happens
expect(result, false);
expect(before.toJson(), after.toJson());
Expand All @@ -36,7 +36,7 @@ void main() async {
formatNumberToNumberedList,
'1.',
2,
(result, before, after) {
(result, before, after, editorState) {
expect(result, true);
expect(after.delta!.toPlainText(), text);
expect(after.type, NumberedListBlockKeys.type);
Expand All @@ -54,7 +54,7 @@ void main() async {
formatNumberToNumberedList,
'1.',
3,
(result, before, after) {
(result, before, after, editorState) {
// nothing happens
expect(result, false);
expect(before.toJson(), after.toJson());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void main() async {
formatDoubleQuoteToQuote,
'"',
1,
(result, before, after) {
(result, before, after, editorState) {
expect(result, true);
expect(after.delta!.toPlainText(), text);
expect(after.type, 'quote');
Expand All @@ -34,7 +34,7 @@ void main() async {
formatDoubleQuoteToQuote,
'"',
2,
(result, before, after) {
(result, before, after, editorState) {
// nothing happens
expect(result, false);
expect(before.toJson(), after.toJson());
Expand Down
5 changes: 3 additions & 2 deletions test/new/block_component/test_character_shortcut.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Future<void> testFormatCharacterShortcut(
CharacterShortcutEvent event,
String prefix,
int index,
void Function(bool result, Node before, Node after) test, {
void Function(bool result, Node before, Node after, EditorState editorState)
test, {
String text = 'Welcome to AppFlowy Editor 🔥!',
}) async {
final document = Document.blank().addParagraph(
Expand All @@ -23,5 +24,5 @@ Future<void> testFormatCharacterShortcut(
final result = await event.execute(editorState);
final after = editorState.getNodesInSelection(selection).first;

test(result, before, after);
test(result, before, after, editorState);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void main() async {
formatEmptyBracketsToUncheckedBox,
'[]',
2,
(result, before, after) {
(result, before, after, editorState) {
expect(result, true);
expect(after.delta!.toPlainText(), text);
expect(after.type, 'todo_list');
Expand All @@ -37,7 +37,7 @@ void main() async {
formatHyphenEmptyBracketsToUncheckedBox,
'-[]',
3,
(result, before, after) {
(result, before, after, editorState) {
expect(result, true);
expect(after.delta!.toPlainText(), text);
expect(after.type, 'todo_list');
Expand All @@ -57,7 +57,7 @@ void main() async {
formatFilledBracketsToCheckedBox,
'[x]',
3,
(result, before, after) {
(result, before, after, editorState) {
expect(result, true);
expect(after.delta!.toPlainText(), text);
expect(after.type, 'todo_list');
Expand All @@ -77,7 +77,7 @@ void main() async {
formatHyphenFilledBracketsToCheckedBox,
'-[x]',
4,
(result, before, after) {
(result, before, after, editorState) {
expect(result, true);
expect(after.delta!.toPlainText(), text);
expect(after.type, 'todo_list');
Expand Down