Skip to content

Commit

Permalink
feat: set workflow zoom range for shortcut (langgenius#7563)
Browse files Browse the repository at this point in the history
  • Loading branch information
YIXIAO0 committed Aug 23, 2024
1 parent 3ac8a28 commit a71fc18
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions web/app/components/workflow/hooks/use-shortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,25 @@ export const useShortcuts = (): void => {
const { handleLayout } = useWorkflowOrganize()

const {
zoomIn,
zoomOut,
zoomTo,
getZoom,
fitView,
} = useReactFlow()

// Zoom out to a minimum of 0.5 for shortcut
const constrainedZoomOut = () => {
const currentZoom = getZoom()
const newZoom = Math.max(currentZoom - 0.1, 0.5)
zoomTo(newZoom)
}

// Zoom in to a maximum of 1 for shortcut
const constrainedZoomIn = () => {
const currentZoom = getZoom()
const newZoom = Math.min(currentZoom + 0.1, 1)
zoomTo(newZoom)
}

const shouldHandleShortcut = useCallback((e: KeyboardEvent) => {
const { showFeaturesPanel } = workflowStore.getState()
return !showFeaturesPanel && !isEventTargetInputArea(e.target as HTMLElement)
Expand Down Expand Up @@ -165,7 +178,7 @@ export const useShortcuts = (): void => {
useKeyPress(`${getKeyboardKeyCodeBySystem('ctrl')}.dash`, (e) => {
if (shouldHandleShortcut(e)) {
e.preventDefault()
zoomOut()
constrainedZoomOut()
handleSyncWorkflowDraft()
}
}, {
Expand All @@ -176,7 +189,7 @@ export const useShortcuts = (): void => {
useKeyPress(`${getKeyboardKeyCodeBySystem('ctrl')}.equalsign`, (e) => {
if (shouldHandleShortcut(e)) {
e.preventDefault()
zoomIn()
constrainedZoomIn()
handleSyncWorkflowDraft()
}
}, {
Expand Down

0 comments on commit a71fc18

Please sign in to comment.