mirror of
https://gitee.com/dify_ai/dify.git
synced 2024-12-02 19:27:48 +08:00
feat: set workflow zoom range for shortcut (#7563)
This commit is contained in:
parent
3ac8a2871e
commit
a71fc18530
@ -37,12 +37,25 @@ export const useShortcuts = (): void => {
|
|||||||
const { handleLayout } = useWorkflowOrganize()
|
const { handleLayout } = useWorkflowOrganize()
|
||||||
|
|
||||||
const {
|
const {
|
||||||
zoomIn,
|
|
||||||
zoomOut,
|
|
||||||
zoomTo,
|
zoomTo,
|
||||||
|
getZoom,
|
||||||
fitView,
|
fitView,
|
||||||
} = useReactFlow()
|
} = 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 shouldHandleShortcut = useCallback((e: KeyboardEvent) => {
|
||||||
const { showFeaturesPanel } = workflowStore.getState()
|
const { showFeaturesPanel } = workflowStore.getState()
|
||||||
return !showFeaturesPanel && !isEventTargetInputArea(e.target as HTMLElement)
|
return !showFeaturesPanel && !isEventTargetInputArea(e.target as HTMLElement)
|
||||||
@ -165,7 +178,7 @@ export const useShortcuts = (): void => {
|
|||||||
useKeyPress(`${getKeyboardKeyCodeBySystem('ctrl')}.dash`, (e) => {
|
useKeyPress(`${getKeyboardKeyCodeBySystem('ctrl')}.dash`, (e) => {
|
||||||
if (shouldHandleShortcut(e)) {
|
if (shouldHandleShortcut(e)) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
zoomOut()
|
constrainedZoomOut()
|
||||||
handleSyncWorkflowDraft()
|
handleSyncWorkflowDraft()
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
@ -176,7 +189,7 @@ export const useShortcuts = (): void => {
|
|||||||
useKeyPress(`${getKeyboardKeyCodeBySystem('ctrl')}.equalsign`, (e) => {
|
useKeyPress(`${getKeyboardKeyCodeBySystem('ctrl')}.equalsign`, (e) => {
|
||||||
if (shouldHandleShortcut(e)) {
|
if (shouldHandleShortcut(e)) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
zoomIn()
|
constrainedZoomIn()
|
||||||
handleSyncWorkflowDraft()
|
handleSyncWorkflowDraft()
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
|
Loading…
Reference in New Issue
Block a user