@@ -59,6 +59,7 @@ describe("registerComposerInlineTokenPaste", () => {
5959 ) ;
6060 registerComposerInlineTokenPaste ( editor , {
6161 createMentionNode : ( path ) => $createTextNode ( `<mention:${ path } >` ) ,
62+ createPastedTextNode : ( text ) => $createTextNode ( `<paste:${ text } >` ) ,
6263 getExpandedAbsoluteOffsetForPoint : ( ) => 0 ,
6364 } ) ;
6465 editor . registerCommand ( PASTE_COMMAND , plainTextFallback , COMMAND_PRIORITY_EDITOR ) ;
@@ -104,6 +105,7 @@ describe("registerComposerInlineTokenPaste", () => {
104105 ) ;
105106 registerComposerInlineTokenPaste ( editor , {
106107 createMentionNode : ( path ) => $createTextNode ( `<mention:${ path } >` ) ,
108+ createPastedTextNode : ( text ) => $createTextNode ( `<paste:${ text } >` ) ,
107109 getExpandedAbsoluteOffsetForPoint : ( ) => 0 ,
108110 } ) ;
109111 editor . registerCommand ( PASTE_COMMAND , plainTextFallback , COMMAND_PRIORITY_EDITOR ) ;
@@ -138,6 +140,7 @@ describe("registerComposerInlineTokenPaste", () => {
138140 ) ;
139141 registerComposerInlineTokenPaste ( editor , {
140142 createMentionNode : ( path ) => $createTextNode ( `<mention:${ path } >` ) ,
143+ createPastedTextNode : ( text ) => $createTextNode ( `<paste:${ text } >` ) ,
141144 getExpandedAbsoluteOffsetForPoint : ( ) => 0 ,
142145 } ) ;
143146 editor . registerCommand ( PASTE_COMMAND , plainTextFallback , COMMAND_PRIORITY_EDITOR ) ;
@@ -158,4 +161,37 @@ describe("registerComposerInlineTokenPaste", () => {
158161 "<mention:@scope/pkg/sub> " ,
159162 ) ;
160163 } ) ;
164+
165+ it ( "turns a large plain-text paste into one atomic presentation node" , ( ) => {
166+ vi . stubGlobal ( "ClipboardEvent" , TestClipboardEvent ) ;
167+ const editor = createEditor ( ) ;
168+ const pastedText = "line of pasted text\n" . repeat ( 20 ) ;
169+ const plainTextFallback = vi . fn ( ( ) => true ) ;
170+
171+ editor . update (
172+ ( ) => {
173+ const paragraph = $createParagraphNode ( ) ;
174+ $getRoot ( ) . append ( paragraph ) ;
175+ paragraph . selectEnd ( ) ;
176+ } ,
177+ { discrete : true } ,
178+ ) ;
179+ registerComposerInlineTokenPaste ( editor , {
180+ createMentionNode : ( path ) => $createTextNode ( `<mention:${ path } >` ) ,
181+ createPastedTextNode : ( text ) => $createTextNode ( `<paste:${ text } >` ) ,
182+ getExpandedAbsoluteOffsetForPoint : ( ) => 0 ,
183+ } ) ;
184+ editor . registerCommand ( PASTE_COMMAND , plainTextFallback , COMMAND_PRIORITY_EDITOR ) ;
185+
186+ const event = new TestClipboardEvent ( pastedText ) ;
187+ editor . update ( ( ) => editor . dispatchCommand ( PASTE_COMMAND , event as ClipboardEvent ) , {
188+ discrete : true ,
189+ } ) ;
190+
191+ expect ( plainTextFallback ) . not . toHaveBeenCalled ( ) ;
192+ expect ( event . defaultPrevented ) . toBe ( true ) ;
193+ expect ( editor . getEditorState ( ) . read ( ( ) => $getRoot ( ) . getTextContent ( ) ) ) . toBe (
194+ `<paste:${ pastedText } >` ,
195+ ) ;
196+ } ) ;
161197} ) ;
0 commit comments