@@ -791,20 +791,16 @@ export class RequisitionHub {
791
791
*/
792
792
public handleRemoteMessage ( message : IEmbeddedMessage ) : void {
793
793
if ( message . command === "paste" && message . data ) {
794
- // Special handling for incoming paste events.
794
+ // Special handling for paste events. An iframe does not get a paste event directly. Instead we have to
795
+ // capture it in the hosting document and forward it as command to our app.
796
+ // Here we convert that command back to a paste event and dispatch it to the active element.
795
797
const element = document . activeElement ;
796
798
const text = message . data . text as string ;
797
799
if ( element && ( element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement ) ) {
798
- const oldValue = element . value ;
799
- const start = element . selectionStart ?? oldValue . length ;
800
- element . value = oldValue . substring ( 0 , start ) + text +
801
- oldValue . substring ( element . selectionEnd ?? start ) ;
802
-
803
- element . selectionStart = start + text . length ; // Set the caret at the end of the new text.
804
- element . selectionEnd = start + text . length ;
805
-
806
- const event = new Event ( "input" , { bubbles : true } ) ;
807
- element . dispatchEvent ( event ) ;
800
+ const dataTransfer = new DataTransfer ( ) ;
801
+ dataTransfer . setData ( "text/plain" , text ) ;
802
+ const pasteEvent = new ClipboardEvent ( "paste" , { clipboardData : dataTransfer } ) ;
803
+ element . dispatchEvent ( pasteEvent ) ;
808
804
}
809
805
810
806
return ;
0 commit comments