Skip to content

Commit

Permalink
fix: workflow zoomin/out shortcuts (#4283)
Browse files Browse the repository at this point in the history
  • Loading branch information
zxhlyh authored May 11, 2024
1 parent 1e45199 commit 13f4ed6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
16 changes: 13 additions & 3 deletions web/app/components/workflow/operator/zoom-in-out.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
import {
getKeyboardKeyCodeBySystem,
getKeyboardKeyNameBySystem,
isEventTargetInputArea,
} from '../utils'
import ShortcutsName from '../shortcuts-name'
import TipPopup from './tip-popup'
Expand Down Expand Up @@ -128,10 +129,13 @@ const ZoomInOut: FC = () => {
})

useKeyPress('shift.1', (e) => {
e.preventDefault()
if (workflowReadOnly)
return

if (isEventTargetInputArea(e.target as HTMLElement))
return

e.preventDefault()
zoomTo(1)
handleSyncWorkflowDraft()
}, {
Expand All @@ -140,10 +144,13 @@ const ZoomInOut: FC = () => {
})

useKeyPress('shift.2', (e) => {
e.preventDefault()
if (workflowReadOnly)
return

if (isEventTargetInputArea(e.target as HTMLElement))
return

e.preventDefault()
zoomTo(2)
handleSyncWorkflowDraft()
}, {
Expand All @@ -152,10 +159,13 @@ const ZoomInOut: FC = () => {
})

useKeyPress('shift.5', (e) => {
e.preventDefault()
if (workflowReadOnly)
return

if (isEventTargetInputArea(e.target as HTMLElement))
return

e.preventDefault()
zoomTo(0.5)
handleSyncWorkflowDraft()
}, {
Expand Down
8 changes: 8 additions & 0 deletions web/app/components/workflow/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,3 +406,11 @@ export const getTopLeftNodePosition = (nodes: Node[]) => {
y: minY,
}
}

export const isEventTargetInputArea = (target: HTMLElement) => {
if (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA')
return true

if (target.contentEditable === 'true')
return true
}

0 comments on commit 13f4ed6

Please sign in to comment.