forked from AppFlowy-IO/appflowy-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: selection menu respects current node direction (AppFlowy-IO#360)
modified insertNodeAfterSelection to copy current node text direction to the node which is going to get inserteded. resolves AppFlowy-IO#331
- Loading branch information
Showing
2 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); | ||
} |