Skip to content

Commit a0d9cc7

Browse files
Add subgraph management keybinds (#6114)
Adds a new keybind to attempt to toggle the promotion state of the currently hovered widget Adds a keybind to open the subgraph configuration panel Neither of these options are given a default binding. Cleans up some incorrect version and icon information that was forgotten about. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-6114-Add-subgraph-management-keybinds-28f6d73d365081e6b6f3c78f99afc094) by [Unito](https://www.unito.io) --------- Co-authored-by: Benjamin Lu <[email protected]>
1 parent d1639c4 commit a0d9cc7

File tree

4 files changed

+51
-7
lines changed

4 files changed

+51
-7
lines changed

src/composables/useCoreCommands.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import {
55
DEFAULT_DARK_COLOR_PALETTE,
66
DEFAULT_LIGHT_COLOR_PALETTE
77
} from '@/constants/coreColorPalettes'
8-
import { promoteRecommendedWidgets } from '@/core/graph/subgraph/proxyWidgetUtils'
8+
import {
9+
promoteRecommendedWidgets,
10+
tryToggleWidgetPromotion
11+
} from '@/core/graph/subgraph/proxyWidgetUtils'
12+
import { showSubgraphNodeDialog } from '@/core/graph/subgraph/useSubgraphNodeDialog'
913
import { t } from '@/i18n'
1014
import {
1115
LGraphEventMode,
@@ -888,7 +892,7 @@ export function useCoreCommands(): ComfyCommand[] {
888892
},
889893
{
890894
id: 'Comfy.Graph.ConvertToSubgraph',
891-
icon: 'pi pi-sitemap',
895+
icon: 'icon-[lucide--shrink]',
892896
label: 'Convert Selection to Subgraph',
893897
versionAdded: '1.20.1',
894898
category: 'essentials' as const,
@@ -916,10 +920,9 @@ export function useCoreCommands(): ComfyCommand[] {
916920
},
917921
{
918922
id: 'Comfy.Graph.UnpackSubgraph',
919-
icon: 'pi pi-sitemap',
923+
icon: 'icon-[lucide--expand]',
920924
label: 'Unpack the selected Subgraph',
921-
versionAdded: '1.20.1',
922-
category: 'essentials' as const,
925+
versionAdded: '1.26.3',
923926
function: () => {
924927
const canvas = canvasStore.getCanvas()
925928
const graph = canvas.subgraph ?? canvas.graph
@@ -931,6 +934,20 @@ export function useCoreCommands(): ComfyCommand[] {
931934
graph.unpackSubgraph(subgraphNode)
932935
}
933936
},
937+
{
938+
id: 'Comfy.Graph.EditSubgraphWidgets',
939+
label: 'Edit Subgraph Widgets',
940+
icon: 'icon-[lucide--settings-2]',
941+
versionAdded: '1.28.5',
942+
function: showSubgraphNodeDialog
943+
},
944+
{
945+
id: 'Comfy.Graph.ToggleWidgetPromotion',
946+
icon: 'icon-[lucide--arrow-left-right]',
947+
label: 'Toggle promotion of hovered widget',
948+
versionAdded: '1.30.1',
949+
function: tryToggleWidgetPromotion
950+
},
934951
{
935952
id: 'Comfy.OpenManagerDialog',
936953
icon: 'mdi mdi-puzzle-outline',

src/core/graph/subgraph/proxyWidgetUtils.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import { parseProxyWidgets } from '@/core/schemas/proxyWidget'
22
import type { ProxyWidgetsProperty } from '@/core/schemas/proxyWidget'
3+
import { t } from '@/i18n'
34
import type {
45
IContextMenuValue,
56
LGraphNode
67
} from '@/lib/litegraph/src/litegraph'
78
import type { SubgraphNode } from '@/lib/litegraph/src/subgraph/SubgraphNode'
89
import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets.ts'
10+
import { useToastStore } from '@/platform/updates/common/toastStore'
11+
import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
912
import { useLitegraphService } from '@/services/litegraphService'
1013
import { useSubgraphNavigationStore } from '@/stores/subgraphNavigationStore'
1114

@@ -63,7 +66,15 @@ function getParentNodes(): SubgraphNode[] {
6366
//or by adding a new event for parent listeners to collect from
6467
const { navigationStack } = useSubgraphNavigationStore()
6568
const subgraph = navigationStack.at(-1)
66-
if (!subgraph) throw new Error("Can't promote widget when not in subgraph")
69+
if (!subgraph) {
70+
useToastStore().add({
71+
severity: 'error',
72+
summary: t('g.error'),
73+
detail: t('subgraphStore.promoteOutsideSubgraph'),
74+
life: 2000
75+
})
76+
return []
77+
}
6778
const parentGraph = navigationStack.at(-2) ?? subgraph.rootGraph
6879
return parentGraph.nodes.filter(
6980
(node): node is SubgraphNode =>
@@ -96,6 +107,21 @@ export function addWidgetPromotionOptions(
96107
})
97108
}
98109
}
110+
export function tryToggleWidgetPromotion() {
111+
const canvas = useCanvasStore().getCanvas()
112+
const [x, y] = canvas.graph_mouse
113+
const node = canvas.graph?.getNodeOnPos(x, y, canvas.visible_nodes)
114+
if (!node) return
115+
const widget = node.getWidgetOnPos(x, y, true)
116+
const parents = getParentNodes()
117+
if (!parents.length || !widget) return
118+
const promotableParents = parents.filter(
119+
(s) => !getProxyWidgets(s).some(matchesPropertyItem([node, widget]))
120+
)
121+
if (promotableParents.length > 0)
122+
promoteWidget(node, widget, promotableParents)
123+
else demoteWidget(node, widget, parents)
124+
}
99125
const recommendedNodes = [
100126
'CLIPTextEncode',
101127
'LoadImage',

src/locales/en/main.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,7 @@
11021102
"overwriteBlueprintTitle": "Overwrite existing blueprint?",
11031103
"overwriteBlueprint": "Saving will overwrite the current blueprint with your changes",
11041104
"blueprintName": "Subgraph name",
1105+
"promoteOutsideSubgraph": "Can't promote widget when not in subgraph",
11051106
"publish": "Publish Subgraph",
11061107
"publishSuccess": "Saved to Nodes Library",
11071108
"publishSuccessMessage": "You can find your subgraph blueprint in the nodes library under \"Subgraph Blueprints\"",

src/services/litegraphService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ export const useLitegraphService = () => {
845845
)
846846
}
847847
if (this.graph && !this.graph.isRootGraph) {
848-
const [x, y] = canvas.canvas_mouse
848+
const [x, y] = canvas.graph_mouse
849849
const overWidget = this.getWidgetOnPos(x, y, true)
850850
if (overWidget) {
851851
addWidgetPromotionOptions(options, overWidget, this)

0 commit comments

Comments
 (0)