From 13f4ed6e0ecb4b57b851a277d99b2e61e9bbc86e Mon Sep 17 00:00:00 2001 From: zxhlyh Date: Sat, 11 May 2024 10:38:12 +0800 Subject: [PATCH] fix: workflow zoomin/out shortcuts (#4283) --- .../components/workflow/operator/zoom-in-out.tsx | 16 +++++++++++++--- web/app/components/workflow/utils.ts | 8 ++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/web/app/components/workflow/operator/zoom-in-out.tsx b/web/app/components/workflow/operator/zoom-in-out.tsx index 6839c1aa04..7de83904fd 100644 --- a/web/app/components/workflow/operator/zoom-in-out.tsx +++ b/web/app/components/workflow/operator/zoom-in-out.tsx @@ -19,6 +19,7 @@ import { import { getKeyboardKeyCodeBySystem, getKeyboardKeyNameBySystem, + isEventTargetInputArea, } from '../utils' import ShortcutsName from '../shortcuts-name' import TipPopup from './tip-popup' @@ -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() }, { @@ -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() }, { @@ -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() }, { diff --git a/web/app/components/workflow/utils.ts b/web/app/components/workflow/utils.ts index d4f6f77d71..e32ba61a36 100644 --- a/web/app/components/workflow/utils.ts +++ b/web/app/components/workflow/utils.ts @@ -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 +}