Browse Source

fix: prevent copy blocks when editor not focus

Ahmad Kholid 2 years ago
parent
commit
08b5580bfa
1 changed files with 8 additions and 3 deletions
  1. 8 3
      src/newtab/pages/workflows/[id].vue

+ 8 - 3
src/newtab/pages/workflows/[id].vue

@@ -117,7 +117,8 @@
             :data="workflow.drawflow"
             :data="workflow.drawflow"
             :disabled="isTeamWorkflow && !haveEditAccess"
             :disabled="isTeamWorkflow && !haveEditAccess"
             :class="{ 'animate-blocks': state.animateBlocks }"
             :class="{ 'animate-blocks': state.animateBlocks }"
-            class="h-screen"
+            class="h-screen workflow-editor"
+            tabindex="0"
             @init="onEditorInit"
             @init="onEditorInit"
             @edit="initEditBlock"
             @edit="initEditBlock"
             @update:node="state.dataChanged = true"
             @update:node="state.dataChanged = true"
@@ -1083,10 +1084,14 @@ function undoRedoCommand(type, { target }) {
 }
 }
 function onKeydown({ ctrlKey, metaKey, shiftKey, key, target }) {
 function onKeydown({ ctrlKey, metaKey, shiftKey, key, target }) {
   const els = ['INPUT', 'SELECT', 'TEXTAREA'];
   const els = ['INPUT', 'SELECT', 'TEXTAREA'];
-  if (els.includes(target.tagName) || target.isContentEditable) return;
+  if (
+    els.includes(target.tagName) ||
+    target.isContentEditable ||
+    !target.classList.contains('workflow-editor')
+  )
+    return;
 
 
   const command = (keyName) => (ctrlKey || metaKey) && keyName === key;
   const command = (keyName) => (ctrlKey || metaKey) && keyName === key;
-
   if (command('c')) {
   if (command('c')) {
     copySelectedElements();
     copySelectedElements();
   } else if (command('v')) {
   } else if (command('v')) {