@@ -36,6 +36,55 @@ void main() {
3636 expect (SuperEditorInspector .findTextInComponent (nodeId).toPlainText (), "Pasted text: This was pasted here" );
3737 });
3838
39+ testAllInputsOnDesktop (
40+ 'pastes some text in the middle of a paragraph, correctly placing the caret at the end of the pasted text' ,
41+ (
42+ tester, {
43+ required TextInputSource inputSource,
44+ }) async {
45+ final testContext = await tester //
46+ .createDocument ()
47+ .withSingleEmptyParagraph ()
48+ .withInputSource (inputSource)
49+ .pump ();
50+
51+ // Place the caret at the empty paragraph.
52+ await tester.placeCaretInParagraph ('1' , 0 );
53+
54+ // Type some text.
55+ switch (inputSource) {
56+ case TextInputSource .keyboard:
57+ await tester.typeKeyboardText ('This is a paragraph' );
58+ case TextInputSource .ime:
59+ await tester.typeImeText ('This is a paragraph' );
60+ }
61+
62+ // Place the cursor somewhere in the middle of the text.
63+ await tester.placeCaretInParagraph ('1' , 8 );
64+
65+ // Simulate pasting multiple lines.
66+ tester
67+ ..simulateClipboard ()
68+ ..setSimulatedClipboardContent ('some content in ' );
69+ if (defaultTargetPlatform == TargetPlatform .macOS) {
70+ await tester.pressCmdV ();
71+ } else {
72+ await tester.pressCtlV ();
73+ }
74+
75+ // Ensure the text is correctly pasted and the caret is placed at the
76+ // end of the pasted text.
77+ final doc = testContext.document;
78+ expect (doc.nodeCount, 1 );
79+ expect ((doc.getNodeAt (0 )! as ParagraphNode ).text.toPlainText (),
80+ 'This is some content in a paragraph' );
81+ final selection = testContext.composer.selection;
82+ expect (selection, isNotNull);
83+ expect (selection! .isCollapsed, isTrue);
84+ expect ((selection.base .nodePosition as TextNodePosition ).offset, 24 );
85+ });
86+
87+
3988 testWidgetsOnApple ('pastes within a list item' , (tester) async {
4089 await tester //
4190 .createDocument ()
0 commit comments