From 95701ab76179f565a7ccd8077050999006931726 Mon Sep 17 00:00:00 2001 From: Chenlei Hu Date: Wed, 4 Sep 2024 20:26:10 -0400 Subject: [PATCH] Add keyboard shortcut for pin/unpin node (#736) * Add keyboard shortcut for pin/unpin node * Add playwright test * Add nextFrame calls * Keyboard event on canvas * disable test --- browser_tests/interaction.spec.ts | 14 ++++++++++++++ src/scripts/app.ts | 11 +++++++++++ 2 files changed, 25 insertions(+) diff --git a/browser_tests/interaction.spec.ts b/browser_tests/interaction.spec.ts index 99c766f1a..432010cc8 100644 --- a/browser_tests/interaction.spec.ts +++ b/browser_tests/interaction.spec.ts @@ -197,6 +197,20 @@ test.describe('Node Interaction', () => { await comfyPage.nextFrame() await expect(comfyPage.canvas).toHaveScreenshot('group-selected-nodes.png') }) + + // Somehow this test fails on GitHub Actions. It works locally. + // https://github.com/Comfy-Org/ComfyUI_frontend/pull/736 + test.skip('Can pin/unpin nodes with keyboard shortcut', async ({ + comfyPage + }) => { + await comfyPage.select2Nodes() + await comfyPage.canvas.press('KeyP') + await comfyPage.nextFrame() + await expect(comfyPage.canvas).toHaveScreenshot('nodes-pinned.png') + await comfyPage.canvas.press('KeyP') + await comfyPage.nextFrame() + await expect(comfyPage.canvas).toHaveScreenshot('nodes-unpinned.png') + }) }) test.describe('Group Interaction', () => { diff --git a/src/scripts/app.ts b/src/scripts/app.ts index 68e9e22c7..8729f816b 100644 --- a/src/scripts/app.ts +++ b/src/scripts/app.ts @@ -1313,6 +1313,17 @@ export class ComfyApp { block_default = true } + // p pin/unpin + if (e.key === 'p') { + if (this.selected_nodes) { + for (const i in this.selected_nodes) { + const node = this.selected_nodes[i] + node.pin() + } + } + block_default = true + } + // Alt + C collapse/uncollapse if (e.key === 'c' && e.altKey) { if (this.selected_nodes) {