Skip to content

Commit f3a7c0d

Browse files
committed
Fixed paste problem with embedded scenarios
Change-Id: Ifcaa414b6cba3024c0118f2cb64e30f6cba62683
1 parent cd2dc39 commit f3a7c0d

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

gui/frontend/src/supplement/Requisitions.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -791,20 +791,16 @@ export class RequisitionHub {
791791
*/
792792
public handleRemoteMessage(message: IEmbeddedMessage): void {
793793
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.
795797
const element = document.activeElement;
796798
const text = message.data.text as string;
797799
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);
808804
}
809805

810806
return;

0 commit comments

Comments
 (0)