Skip to content

Commit bbf7b48

Browse files
comfy-pr-botchristian-byrnegithub-actions
authored
[backport 1.25] [feat] Make hotkey for exiting subgraphs configurable in user keybindings (#4914)
Co-authored-by: Christian Byrne <cbyrne@comfy.org> Co-authored-by: github-actions <github-actions@github.com>
1 parent d1434d1 commit bbf7b48

File tree

22 files changed

+370
-13
lines changed

22 files changed

+370
-13
lines changed

browser_tests/tests/subgraph.spec.ts

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,4 +528,103 @@ test.describe('Subgraph Operations', () => {
528528
expect(finalCount).toBe(parentCount)
529529
})
530530
})
531+
532+
test.describe('Navigation Hotkeys', () => {
533+
test.beforeEach(async ({ comfyPage }) => {
534+
await comfyPage.setSetting('Comfy.UseNewMenu', 'Top')
535+
})
536+
537+
test('Navigation hotkey can be customized', async ({ comfyPage }) => {
538+
await comfyPage.loadWorkflow('basic-subgraph')
539+
await comfyPage.nextFrame()
540+
541+
// Change the Exit Subgraph keybinding from Escape to Alt+Q
542+
await comfyPage.setSetting('Comfy.Keybinding.NewBindings', [
543+
{
544+
commandId: 'Comfy.Graph.ExitSubgraph',
545+
combo: {
546+
key: 'q',
547+
ctrl: false,
548+
alt: true,
549+
shift: false
550+
}
551+
}
552+
])
553+
554+
await comfyPage.setSetting('Comfy.Keybinding.UnsetBindings', [
555+
{
556+
commandId: 'Comfy.Graph.ExitSubgraph',
557+
combo: {
558+
key: 'Escape',
559+
ctrl: false,
560+
alt: false,
561+
shift: false
562+
}
563+
}
564+
])
565+
566+
// Reload the page
567+
await comfyPage.page.reload()
568+
await comfyPage.page.waitForTimeout(1024)
569+
570+
// Navigate into subgraph
571+
const subgraphNode = await comfyPage.getNodeRefById('2')
572+
await subgraphNode.navigateIntoSubgraph()
573+
await comfyPage.page.waitForSelector(SELECTORS.breadcrumb)
574+
575+
// Verify we're in a subgraph
576+
expect(await isInSubgraph(comfyPage)).toBe(true)
577+
578+
// Test that Escape no longer exits subgraph
579+
await comfyPage.page.keyboard.press('Escape')
580+
await comfyPage.nextFrame()
581+
if (!(await isInSubgraph(comfyPage))) {
582+
throw new Error('Not in subgraph')
583+
}
584+
585+
// Test that Alt+Q now exits subgraph
586+
await comfyPage.page.keyboard.press('Alt+q')
587+
await comfyPage.nextFrame()
588+
expect(await isInSubgraph(comfyPage)).toBe(false)
589+
})
590+
591+
test('Escape prioritizes closing dialogs over exiting subgraph', async ({
592+
comfyPage
593+
}) => {
594+
await comfyPage.loadWorkflow('basic-subgraph')
595+
await comfyPage.nextFrame()
596+
597+
const subgraphNode = await comfyPage.getNodeRefById('2')
598+
await subgraphNode.navigateIntoSubgraph()
599+
await comfyPage.page.waitForSelector(SELECTORS.breadcrumb)
600+
601+
// Verify we're in a subgraph
602+
if (!(await isInSubgraph(comfyPage))) {
603+
throw new Error('Not in subgraph')
604+
}
605+
606+
// Open settings dialog using hotkey
607+
await comfyPage.page.keyboard.press('Control+,')
608+
await comfyPage.page.waitForSelector('.settings-container', {
609+
state: 'visible'
610+
})
611+
612+
// Press Escape - should close dialog, not exit subgraph
613+
await comfyPage.page.keyboard.press('Escape')
614+
await comfyPage.nextFrame()
615+
616+
// Dialog should be closed
617+
await expect(
618+
comfyPage.page.locator('.settings-container')
619+
).not.toBeVisible()
620+
621+
// Should still be in subgraph
622+
expect(await isInSubgraph(comfyPage)).toBe(true)
623+
624+
// Press Escape again - now should exit subgraph
625+
await comfyPage.page.keyboard.press('Escape')
626+
await comfyPage.nextFrame()
627+
expect(await isInSubgraph(comfyPage)).toBe(false)
628+
})
629+
})
531630
})

src/components/breadcrumb/SubgraphBreadcrumb.vue

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
</template>
3333

3434
<script setup lang="ts">
35-
import { useEventListener } from '@vueuse/core'
3635
import Breadcrumb from 'primevue/breadcrumb'
3736
import type { MenuItem } from 'primevue/menuitem'
3837
import { computed, onUpdated, ref, watch } from 'vue'
@@ -98,18 +97,6 @@ const home = computed(() => ({
9897
}
9998
}))
10099
101-
// Escape exits from the current subgraph.
102-
useEventListener(document, 'keydown', (event) => {
103-
if (event.key === 'Escape') {
104-
const canvas = useCanvasStore().getCanvas()
105-
if (!canvas.graph) throw new TypeError('Canvas has no graph')
106-
107-
canvas.setGraph(
108-
navigationStore.navigationStack.at(-2) ?? canvas.graph.rootGraph
109-
)
110-
}
111-
})
112-
113100
// Check for overflow on breadcrumb items and collapse/expand the breadcrumb to fit
114101
let overflowObserver: ReturnType<typeof useOverflowObserver> | undefined
115102
watch(breadcrumbElement, (el) => {

src/composables/useCoreCommands.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { useExecutionStore } from '@/stores/executionStore'
2323
import { useCanvasStore, useTitleEditorStore } from '@/stores/graphStore'
2424
import { useQueueSettingsStore, useQueueStore } from '@/stores/queueStore'
2525
import { useSettingStore } from '@/stores/settingStore'
26+
import { useSubgraphNavigationStore } from '@/stores/subgraphNavigationStore'
2627
import { useToastStore } from '@/stores/toastStore'
2728
import { type ComfyWorkflow, useWorkflowStore } from '@/stores/workflowStore'
2829
import { useBottomPanelStore } from '@/stores/workspace/bottomPanelStore'
@@ -805,6 +806,21 @@ export function useCoreCommands(): ComfyCommand[] {
805806
function: () => {
806807
bottomPanelStore.togglePanel('shortcuts')
807808
}
809+
},
810+
{
811+
id: 'Comfy.Graph.ExitSubgraph',
812+
icon: 'pi pi-arrow-up',
813+
label: 'Exit Subgraph',
814+
versionAdded: '1.20.1',
815+
function: () => {
816+
const canvas = useCanvasStore().getCanvas()
817+
const navigationStore = useSubgraphNavigationStore()
818+
if (!canvas.graph) return
819+
820+
canvas.setGraph(
821+
navigationStore.navigationStack.at(-2) ?? canvas.graph.rootGraph
822+
)
823+
}
808824
}
809825
]
810826

src/constants/coreKeybindings.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,5 +190,11 @@ export const CORE_KEYBINDINGS: Keybinding[] = [
190190
key: 'k'
191191
},
192192
commandId: 'Workspace.ToggleBottomPanel.Shortcuts'
193+
},
194+
{
195+
combo: {
196+
key: 'Escape'
197+
},
198+
commandId: 'Comfy.Graph.ExitSubgraph'
193199
}
194200
]

src/locales/en/commands.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@
119119
"Comfy_Graph_ConvertToSubgraph": {
120120
"label": "Convert Selection to Subgraph"
121121
},
122+
"Comfy_Graph_ExitSubgraph": {
123+
"label": "Exit Subgraph"
124+
},
122125
"Comfy_Graph_FitGroupToContents": {
123126
"label": "Fit Group To Contents"
124127
},

src/locales/en/main.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,7 @@
974974
"Export (API)": "Export (API)",
975975
"Give Feedback": "Give Feedback",
976976
"Convert Selection to Subgraph": "Convert Selection to Subgraph",
977+
"Exit Subgraph": "Exit Subgraph",
977978
"Fit Group To Contents": "Fit Group To Contents",
978979
"Group Selected Nodes": "Group Selected Nodes",
979980
"Convert selected nodes to group node": "Convert selected nodes to group node",

src/locales/es/commands.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@
119119
"Comfy_Graph_ConvertToSubgraph": {
120120
"label": "Convertir selección en subgrafo"
121121
},
122+
"Comfy_Graph_ExitSubgraph": {
123+
"label": "Salir de subgrafo"
124+
},
122125
"Comfy_Graph_FitGroupToContents": {
123126
"label": "Ajustar grupo al contenido"
124127
},

src/locales/es/main.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,7 @@
765765
"Desktop User Guide": "Guía de usuario de escritorio",
766766
"Duplicate Current Workflow": "Duplicar flujo de trabajo actual",
767767
"Edit": "Editar",
768+
"Exit Subgraph": "Salir de subgrafo",
768769
"Export": "Exportar",
769770
"Export (API)": "Exportar (API)",
770771
"Fit Group To Contents": "Ajustar grupo a contenidos",

src/locales/fr/commands.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@
119119
"Comfy_Graph_ConvertToSubgraph": {
120120
"label": "Convertir la sélection en sous-graphe"
121121
},
122+
"Comfy_Graph_ExitSubgraph": {
123+
"label": "Quitter le sous-graphe"
124+
},
122125
"Comfy_Graph_FitGroupToContents": {
123126
"label": "Ajuster le groupe au contenu"
124127
},

src/locales/fr/main.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,7 @@
765765
"Desktop User Guide": "Guide de l'utilisateur de bureau",
766766
"Duplicate Current Workflow": "Dupliquer le flux de travail actuel",
767767
"Edit": "Éditer",
768+
"Exit Subgraph": "Quitter le sous-graphe",
768769
"Export": "Exporter",
769770
"Export (API)": "Exporter (API)",
770771
"Fit Group To Contents": "Ajuster le groupe au contenu",

0 commit comments

Comments
 (0)