mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-29 10:42:44 +00:00
[fix] Fix viewport sync in minimap and subgraphs navigation (#4644)
This commit is contained in:
@@ -8,7 +8,6 @@ import { api } from '@/scripts/api'
|
|||||||
import { app } from '@/scripts/app'
|
import { app } from '@/scripts/app'
|
||||||
import { useCanvasStore } from '@/stores/graphStore'
|
import { useCanvasStore } from '@/stores/graphStore'
|
||||||
import { useSettingStore } from '@/stores/settingStore'
|
import { useSettingStore } from '@/stores/settingStore'
|
||||||
import { useWorkflowStore } from '@/stores/workflowStore'
|
|
||||||
import { useColorPaletteStore } from '@/stores/workspace/colorPaletteStore'
|
import { useColorPaletteStore } from '@/stores/workspace/colorPaletteStore'
|
||||||
|
|
||||||
interface GraphCallbacks {
|
interface GraphCallbacks {
|
||||||
@@ -21,7 +20,6 @@ export function useMinimap() {
|
|||||||
const settingStore = useSettingStore()
|
const settingStore = useSettingStore()
|
||||||
const canvasStore = useCanvasStore()
|
const canvasStore = useCanvasStore()
|
||||||
const colorPaletteStore = useColorPaletteStore()
|
const colorPaletteStore = useColorPaletteStore()
|
||||||
const workflowStore = useWorkflowStore()
|
|
||||||
|
|
||||||
const containerRef = ref<HTMLDivElement>()
|
const containerRef = ref<HTMLDivElement>()
|
||||||
const canvasRef = ref<HTMLCanvasElement>()
|
const canvasRef = ref<HTMLCanvasElement>()
|
||||||
@@ -110,29 +108,6 @@ export function useMinimap() {
|
|||||||
const canvas = computed(() => canvasStore.canvas)
|
const canvas = computed(() => canvasStore.canvas)
|
||||||
const graph = ref(app.canvas?.graph)
|
const graph = ref(app.canvas?.graph)
|
||||||
|
|
||||||
// Update graph ref when subgraph context changes
|
|
||||||
watch(
|
|
||||||
() => workflowStore.activeSubgraph,
|
|
||||||
() => {
|
|
||||||
graph.value = app.canvas?.graph
|
|
||||||
// Force viewport update when switching subgraphs
|
|
||||||
if (initialized.value && visible.value) {
|
|
||||||
updateViewport()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// Update viewport when switching workflows
|
|
||||||
watch(
|
|
||||||
() => workflowStore.activeWorkflow,
|
|
||||||
() => {
|
|
||||||
// Force viewport update when switching workflows
|
|
||||||
if (initialized.value && visible.value) {
|
|
||||||
updateViewport()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
const containerStyles = computed(() => ({
|
const containerStyles = computed(() => ({
|
||||||
width: `${width}px`,
|
width: `${width}px`,
|
||||||
height: `${height}px`,
|
height: `${height}px`,
|
||||||
@@ -377,6 +352,8 @@ export function useMinimap() {
|
|||||||
needsBoundsUpdate.value = false
|
needsBoundsUpdate.value = false
|
||||||
updateFlags.value.bounds = false
|
updateFlags.value.bounds = false
|
||||||
needsFullRedraw.value = true
|
needsFullRedraw.value = true
|
||||||
|
// When bounds change, we need to update the viewport position
|
||||||
|
updateFlags.value.viewport = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@@ -386,6 +363,11 @@ export function useMinimap() {
|
|||||||
) {
|
) {
|
||||||
renderMinimap()
|
renderMinimap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update viewport if needed (e.g., after bounds change)
|
||||||
|
if (updateFlags.value.viewport) {
|
||||||
|
updateViewport()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const checkForChanges = useThrottleFn(() => {
|
const checkForChanges = useThrottleFn(() => {
|
||||||
@@ -660,7 +642,7 @@ export function useMinimap() {
|
|||||||
await init()
|
await init()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ immediate: true }
|
{ immediate: true, flush: 'post' }
|
||||||
)
|
)
|
||||||
|
|
||||||
watch(visible, async (isVisible) => {
|
watch(visible, async (isVisible) => {
|
||||||
@@ -678,6 +660,8 @@ export function useMinimap() {
|
|||||||
|
|
||||||
await nextTick()
|
await nextTick()
|
||||||
|
|
||||||
|
await nextTick()
|
||||||
|
|
||||||
updateMinimap()
|
updateMinimap()
|
||||||
updateViewport()
|
updateViewport()
|
||||||
resumeChangeDetection()
|
resumeChangeDetection()
|
||||||
|
|||||||
@@ -33,6 +33,17 @@ export const useSubgraphNavigationStore = defineStore(
|
|||||||
maxSize: 32
|
maxSize: 32
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the ID of the root graph for the currently active workflow.
|
||||||
|
* @returns The ID of the root graph for the currently active workflow.
|
||||||
|
*/
|
||||||
|
const getCurrentRootGraphId = () => {
|
||||||
|
const canvas = canvasStore.getCanvas()
|
||||||
|
if (!canvas) return 'root'
|
||||||
|
|
||||||
|
return canvas.graph?.rootGraph?.id ?? 'root'
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A stack representing subgraph navigation history from the root graph to
|
* A stack representing subgraph navigation history from the root graph to
|
||||||
* the current opened subgraph.
|
* the current opened subgraph.
|
||||||
@@ -117,13 +128,13 @@ export const useSubgraphNavigationStore = defineStore(
|
|||||||
saveViewport(prevSubgraph.id)
|
saveViewport(prevSubgraph.id)
|
||||||
} else if (!prevSubgraph && subgraph) {
|
} else if (!prevSubgraph && subgraph) {
|
||||||
// Leaving root graph to enter a subgraph
|
// Leaving root graph to enter a subgraph
|
||||||
saveViewport('root')
|
saveViewport(getCurrentRootGraphId())
|
||||||
}
|
}
|
||||||
|
|
||||||
const isInRootGraph = !subgraph
|
const isInRootGraph = !subgraph
|
||||||
if (isInRootGraph) {
|
if (isInRootGraph) {
|
||||||
idStack.value.length = 0
|
idStack.value.length = 0
|
||||||
restoreViewport('root')
|
restoreViewport(getCurrentRootGraphId())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user