Skip to content

Commit 6099b08

Browse files
committed
fit view:
- fit view to canvas selection - fit view to whole graph when nothing is selected - add button to graph canvas menu - assign default keybinding '.'
1 parent 3148c90 commit 6099b08

File tree

5 files changed

+45
-1
lines changed

5 files changed

+45
-1
lines changed

src/components/graph/GraphCanvasMenu.vue

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,19 @@
1616
@mousedown="repeat('Comfy.Canvas.ZoomOut')"
1717
@mouseup="stopRepeat"
1818
/>
19+
<hr />
1920
<Button
2021
severity="secondary"
2122
icon="pi pi-expand"
2223
v-tooltip.left="t('graphCanvasMenu.resetView')"
2324
@click="() => commandStore.execute('Comfy.Canvas.ResetView')"
2425
/>
26+
<Button
27+
severity="secondary"
28+
icon="pi pi-arrow-down-left-and-arrow-up-right-to-center"
29+
v-tooltip.left="t('graphCanvasMenu.fitView')"
30+
@click="() => commandStore.execute('Comfy.Canvas.FitView')"
31+
/>
2532
<Button
2633
severity="secondary"
2734
v-tooltip.left="
@@ -96,4 +103,9 @@ const stopRepeat = () => {
96103
margin: 0;
97104
border-radius: 0;
98105
}
106+
107+
.p-buttongroup-vertical hr {
108+
margin: 0;
109+
border-color: var(--p-panel-border-color);
110+
}
99111
</style>

src/i18n.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ const messages = {
111111
zoomIn: 'Zoom In',
112112
zoomOut: 'Zoom Out',
113113
resetView: 'Reset View',
114+
fitView: 'Fit View',
114115
selectMode: 'Select Mode',
115116
panMode: 'Pan Mode',
116117
toggleLinkVisibility: 'Toggle Link Visibility'
@@ -225,6 +226,7 @@ const messages = {
225226
zoomIn: '放大',
226227
zoomOut: '缩小',
227228
resetView: '重置视图',
229+
fitView: 'Fit View',
228230
selectMode: '选择模式',
229231
panMode: '平移模式',
230232
toggleLinkVisibility: '切换链接可见性'
@@ -342,6 +344,7 @@ const messages = {
342344
zoomIn: 'Увеличить',
343345
zoomOut: 'Уменьшить',
344346
resetView: 'Сбросить вид',
347+
fitView: 'Fit View',
345348
selectMode: 'Выбрать режим',
346349
panMode: 'Режим панорамирования',
347350
toggleLinkVisibility: 'Переключить видимость ссылок'

src/scripts/app.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { ComfyAppMenu } from './ui/menu/index'
2727
import { getStorageValue } from './utils'
2828
import { ComfyWorkflowManager, ComfyWorkflow } from './workflows'
2929
import {
30+
LGraphGroup,
3031
LGraphCanvas,
3132
LGraph,
3233
LGraphNode,
@@ -2977,7 +2978,22 @@ export class ComfyApp {
29772978
public goToNode(nodeId: NodeId) {
29782979
const graphNode = this.graph.getNodeById(nodeId)
29792980
if (!graphNode) return
2980-
this.canvas.animateToNode(graphNode)
2981+
this.canvas.animateToBounds(LGraphGroup.createBounds([graphNode]))
2982+
}
2983+
2984+
/**
2985+
* Fits the view to the selected nodes with animation.
2986+
* If nothing is selected, the view is fitted around all nodes in the graph.
2987+
*/
2988+
fitView() {
2989+
let selection: LGraphNode[]
2990+
selection = Array.from(app.canvas.selectedItems.values())
2991+
.map((i) => this.graph.getNodeById(i.id))
2992+
.filter((i) => i !== null)
2993+
if (selection.length === 0) {
2994+
selection = this.graph.nodes
2995+
}
2996+
this.canvas.animateToBounds(LGraphGroup.createBounds(selection))
29812997
}
29822998
}
29832999

src/stores/commandStore.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,12 @@ export const useCommandStore = defineStore('command', () => {
295295
app.canvas.setDirty(true, true)
296296
}
297297
},
298+
{
299+
id: 'Comfy.Canvas.FitView',
300+
icon: 'pi pi-arrow-down-left-and-arrow-up-right-to-center',
301+
label: 'Fit view to selected nodes',
302+
function: () => app.fitView()
303+
},
298304
{
299305
id: 'Comfy.Canvas.ToggleLock',
300306
icon: 'pi pi-lock',

src/stores/coreKeybindings.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ export const CORE_KEYBINDINGS: Keybinding[] = [
130130
commandId: 'Comfy.Canvas.ZoomOut',
131131
targetSelector: '#graph-canvas'
132132
},
133+
{
134+
combo: {
135+
key: '.'
136+
},
137+
commandId: 'Comfy.Canvas.FitView',
138+
targetSelector: '#graph-canvas'
139+
},
133140
{
134141
combo: {
135142
key: 'p'

0 commit comments

Comments
 (0)