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: selection menu respect current node direction #360

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 @@ -48,6 +48,11 @@ bool insertNodeAfterSelection(
if (currentNode == null) {
return false;
}
node.updateAttributes({
blockComponentTextDirection:
currentNode.attributes[blockComponentTextDirection]
});

final transaction = editorState.transaction;
final delta = currentNode.delta;
if (delta != null && delta.isEmpty) {
Expand Down
116 changes: 116 additions & 0 deletions test/service/format_rich_text_style_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor/src/service/default_text_operations/format_rich_text_style.dart';
import 'package:flutter_test/flutter_test.dart';
import '../new/infra/testable_editor.dart';

void main() async {
setUpAll(() {
TestWidgetsFlutterBinding.ensureInitialized();
});

group('format rich text style', () {
testWidgets('insertNodeAfterSelection', (tester) async {
final editor = tester.editor..addParagraph();
await editor.startTesting();

await editor.updateSelection(Selection.collapse([0], 0));
final inserted =
insertNodeAfterSelection(editor.editorState, paragraphNode());
await tester.pumpAndSettle();

expect(inserted, true);
final node = editor.nodeAtPath([1])!;
expect(node.attributes[blockComponentTextDirection], null);

await editor.dispose();
});

testWidgets('insertNodeAfterSelection on empty node', (tester) async {
final editor = tester.editor..addNode(paragraphNode());
await editor.startTesting();

await editor.updateSelection(Selection.collapse([0], 0));
final inserted =
insertNodeAfterSelection(editor.editorState, paragraphNode());
await tester.pumpAndSettle();

expect(inserted, true);
final node = editor.nodeAtPath([0])!;
expect(node.attributes[blockComponentTextDirection], null);

await editor.dispose();
});

testWidgets('insertNodeAfterSelection on node with text direction',
(tester) async {
final editor = tester.editor
..addNode(
paragraphNode(
text: ' ',
textDirection: blockComponentTextDirectionAuto,
),
);
await editor.startTesting();

await editor.updateSelection(Selection.collapse([0], 0));
final inserted =
insertNodeAfterSelection(editor.editorState, paragraphNode());
await tester.pumpAndSettle();

final node = editor.nodeAtPath([1])!;
expect(inserted, true);
expect(
node.attributes[blockComponentTextDirection],
blockComponentTextDirectionAuto,
);

await editor.dispose();
});

testWidgets('insertNodeAfterSelection on empty node with text direction',
(tester) async {
final editor = tester.editor
..addNode(
paragraphNode(textDirection: blockComponentTextDirectionLTR),
);
await editor.startTesting();

await editor.updateSelection(Selection.collapse([0], 0));
final inserted =
insertNodeAfterSelection(editor.editorState, paragraphNode());
await tester.pumpAndSettle();

final node = editor.nodeAtPath([0])!;
expect(inserted, true);
expect(
node.attributes[blockComponentTextDirection],
blockComponentTextDirectionLTR,
);

await editor.dispose();
});

testWidgets('insertHeadingAfterSelection on rtl node', (tester) async {
final editor = tester.editor
..addNode(
paragraphNode(
text: ' ',
textDirection: blockComponentTextDirectionRTL,
),
);
await editor.startTesting();

await editor.updateSelection(Selection.collapse([0], 0));
insertHeadingAfterSelection(editor.editorState, 1);
await tester.pumpAndSettle();

final node = editor.nodeAtPath([1])!;
expect(
node.attributes[blockComponentTextDirection],
blockComponentTextDirectionRTL,
);

await editor.dispose();
});
});
}