@@ -51,7 +51,7 @@ import { selectSelectionMode, selectShouldSnapToGrid } from 'features/nodes/stor
5151import { NO_DRAG_CLASS , NO_PAN_CLASS , NO_WHEEL_CLASS } from 'features/nodes/types/constants' ;
5252import type { AnyEdge , AnyNode } from 'features/nodes/types/invocation' ;
5353import { useRegisteredHotkeys } from 'features/system/components/HotkeysModal/useHotkeyData' ;
54- import type { CSSProperties , MouseEvent } from 'react' ;
54+ import type { CSSProperties , MouseEvent , RefObject } from 'react' ;
5555import { memo , useCallback , useMemo , useRef } from 'react' ;
5656import { useHotkeys } from 'react-hotkeys-hook' ;
5757
@@ -61,6 +61,7 @@ import InvocationDefaultEdge from './edges/InvocationDefaultEdge';
6161import CurrentImageNode from './nodes/CurrentImage/CurrentImageNode' ;
6262import InvocationNodeWrapper from './nodes/Invocation/InvocationNodeWrapper' ;
6363import NotesNode from './nodes/Notes/NotesNode' ;
64+ import { isWorkflowHotkeyEnabled , shouldIgnoreWorkflowCopyHotkey } from './workflowHotkeys' ;
6465
6566const edgeTypes = {
6667 collapsed : InvocationCollapsedEdge ,
@@ -248,14 +249,14 @@ export const Flow = memo(() => {
248249 >
249250 < Background gap = { snapGrid } offset = { snapGrid } />
250251 </ ReactFlow >
251- < HotkeyIsolator />
252+ < HotkeyIsolator flowWrapper = { flowWrapper } />
252253 </ >
253254 ) ;
254255} ) ;
255256
256257Flow . displayName = 'Flow' ;
257258
258- const HotkeyIsolator = memo ( ( ) => {
259+ const HotkeyIsolator = memo ( ( { flowWrapper } : { flowWrapper : RefObject < HTMLDivElement > } ) => {
259260 const mayUndo = useAppSelector ( selectMayUndo ) ;
260261 const mayRedo = useAppSelector ( selectMayRedo ) ;
261262
@@ -270,8 +271,12 @@ const HotkeyIsolator = memo(() => {
270271 id : 'copySelection' ,
271272 category : 'workflows' ,
272273 callback : copySelection ,
273- options : { enabled : isWorkflowsFocused , preventDefault : true } ,
274- dependencies : [ copySelection ] ,
274+ options : {
275+ enabled : isWorkflowHotkeyEnabled ( isWorkflowsFocused ) ,
276+ preventDefault : true ,
277+ ignoreEventWhen : ( ) => shouldIgnoreWorkflowCopyHotkey ( window . getSelection ( ) , flowWrapper . current ) ,
278+ } ,
279+ dependencies : [ copySelection , isWorkflowsFocused ] ,
275280 } ) ;
276281
277282 const selectAll = useCallback ( ( ) => {
@@ -299,23 +304,23 @@ const HotkeyIsolator = memo(() => {
299304 id : 'selectAll' ,
300305 category : 'workflows' ,
301306 callback : selectAll ,
302- options : { enabled : isWorkflowsFocused , preventDefault : true } ,
307+ options : { enabled : isWorkflowHotkeyEnabled ( isWorkflowsFocused ) , preventDefault : true } ,
303308 dependencies : [ selectAll , isWorkflowsFocused ] ,
304309 } ) ;
305310
306311 useRegisteredHotkeys ( {
307312 id : 'pasteSelection' ,
308313 category : 'workflows' ,
309314 callback : pasteSelection ,
310- options : { enabled : isWorkflowsFocused , preventDefault : true } ,
315+ options : { enabled : isWorkflowHotkeyEnabled ( isWorkflowsFocused ) , preventDefault : true } ,
311316 dependencies : [ pasteSelection , isWorkflowsFocused ] ,
312317 } ) ;
313318
314319 useRegisteredHotkeys ( {
315320 id : 'pasteSelectionWithEdges' ,
316321 category : 'workflows' ,
317322 callback : pasteSelectionWithEdges ,
318- options : { enabled : isWorkflowsFocused , preventDefault : true } ,
323+ options : { enabled : isWorkflowHotkeyEnabled ( isWorkflowsFocused ) , preventDefault : true } ,
319324 dependencies : [ pasteSelectionWithEdges , isWorkflowsFocused ] ,
320325 } ) ;
321326
@@ -325,7 +330,7 @@ const HotkeyIsolator = memo(() => {
325330 callback : ( ) => {
326331 store . dispatch ( undo ( ) ) ;
327332 } ,
328- options : { enabled : isWorkflowsFocused && mayUndo , preventDefault : true } ,
333+ options : { enabled : isWorkflowHotkeyEnabled ( isWorkflowsFocused ) && mayUndo , preventDefault : true } ,
329334 dependencies : [ store , mayUndo , isWorkflowsFocused ] ,
330335 } ) ;
331336
@@ -335,7 +340,7 @@ const HotkeyIsolator = memo(() => {
335340 callback : ( ) => {
336341 store . dispatch ( redo ( ) ) ;
337342 } ,
338- options : { enabled : isWorkflowsFocused && mayRedo , preventDefault : true } ,
343+ options : { enabled : isWorkflowHotkeyEnabled ( isWorkflowsFocused ) && mayRedo , preventDefault : true } ,
339344 dependencies : [ store , mayRedo , isWorkflowsFocused ] ,
340345 } ) ;
341346
@@ -373,7 +378,7 @@ const HotkeyIsolator = memo(() => {
373378 id : 'deleteSelection' ,
374379 category : 'workflows' ,
375380 callback : deleteSelection ,
376- options : { preventDefault : true , enabled : isWorkflowsFocused } ,
381+ options : { preventDefault : true , enabled : isWorkflowHotkeyEnabled ( isWorkflowsFocused ) } ,
377382 dependencies : [ deleteSelection , isWorkflowsFocused ] ,
378383 } ) ;
379384
0 commit comments