From fd45fc50ed3134da0a9e8952dc1bac06adbc6808 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Wed, 9 Jun 2021 16:58:58 +0200 Subject: [PATCH] Fix copying selected text in workflow editor The only text we could copy had to be within input boxes, but we may want to also copy text from the error / upgrade message modal or from the help text or other links. So if there's currently any highlighted text we skip the workflow copy logic. --- .../src/components/Workflow/Editor/modules/canvas.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/client/src/components/Workflow/Editor/modules/canvas.js b/client/src/components/Workflow/Editor/modules/canvas.js index 5b49b0f222b..df757a63d69 100644 --- a/client/src/components/Workflow/Editor/modules/canvas.js +++ b/client/src/components/Workflow/Editor/modules/canvas.js @@ -220,12 +220,17 @@ class CanvasManager { } init_copy_paste() { /* - Both of these copy/paste event bindings check the active element + The copy/paste event bindings check the active element and, if it's one of the text inputs, skip the workflow copy/paste logic so we don't interfere with standard copy/paste functionality. + The copy binding also skips the node copy if text is currently highlighted. */ document.addEventListener("copy", (e) => { - if (document.activeElement && !inputElementTypes.includes(document.activeElement.type)) { + if ( + document.activeElement && + !inputElementTypes.includes(document.activeElement.type) && + !document.getSelection().toString() + ) { if (this.app.activeNode && this.app.activeNode.type !== "subworkflow") { e.clipboardData.setData( "application/json", @@ -233,8 +238,8 @@ class CanvasManager { nodeId: this.app.activeNode.id, }) ); + e.preventDefault(); } - e.preventDefault(); } }); document.addEventListener("paste", (e) => {