Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group selected nodes by Ctrl + g #663

Merged
merged 5 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions browser_tests/interaction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,16 @@ test.describe('Node Interaction', () => {
})
expect(await comfyPage.page.locator('.node-title-editor').count()).toBe(0)
})

test('Can group selected nodes', async ({ comfyPage }) => {
await comfyPage.setSetting('Comfy.GroupSelectedNodes.Padding', 10)
await comfyPage.select2Nodes()
await comfyPage.page.keyboard.down('Control')
await comfyPage.page.keyboard.press('KeyG')
await comfyPage.page.keyboard.up('Control')
await comfyPage.nextFrame()
await expect(comfyPage.canvas).toHaveScreenshot('group-selected-nodes.png')
})
})

test.describe('Canvas Interaction', () => {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
},
"dependencies": {
"@atlaskit/pragmatic-drag-and-drop": "^1.2.1",
"@comfyorg/litegraph": "^0.7.52",
"@comfyorg/litegraph": "^0.7.54",
"@primevue/themes": "^4.0.0-rc.2",
"@vitejs/plugin-vue": "^5.0.5",
"@vueuse/core": "^11.0.0",
Expand Down
3 changes: 2 additions & 1 deletion src/extensions/core/keybinds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ app.registerExtension({
s: '#comfy-save-button',
o: '#comfy-file-input',
Backspace: '#comfy-clear-button',
d: '#comfy-load-default-button'
d: '#comfy-load-default-button',
g: '#comfy-group-selected-nodes-button'
}

const modifierKeybindId = modifierKeyIdMap[event.key]
Expand Down
1 change: 1 addition & 0 deletions src/scripts/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import { useSettingStore } from '@/stores/settingStore'
import { useToastStore } from '@/stores/toastStore'
import type { ToastMessageOptions } from 'primevue/toast'
import { useWorkspaceStore } from '@/stores/workspaceStateStore'
import { LGraphGroup } from '@comfyorg/litegraph'

export const ANIM_PREVIEW_WIDGET = '$$comfy_animation_preview'

Expand Down
28 changes: 28 additions & 0 deletions src/scripts/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { ComfySettingsDialog } from './ui/settings'
import { ComfyApp, app } from './app'
import { TaskItem } from '@/types/apiTypes'
import { showSettingsDialog } from '@/services/dialogService'
import { useToastStore } from '@/stores/toastStore'
import { LGraphGroup } from '@comfyorg/litegraph'
import { useSettingStore } from '@/stores/settingStore'

export const ComfyDialog = _ComfyDialog

Expand Down Expand Up @@ -756,6 +759,31 @@ export class ComfyUI {
onclick: async () => {
app.resetView()
}
}),
$el('button', {
id: 'comfy-group-selected-nodes-button',
textContent: 'Group',
hidden: true,
onclick: () => {
if (
!app.canvas.selected_nodes ||
Object.keys(app.canvas.selected_nodes).length === 0
) {
useToastStore().add({
severity: 'error',
summary: 'No nodes selected',
detail: 'Please select nodes to group',
life: 3000
})
return
}
const group = new LGraphGroup()
const padding = useSettingStore().get(
'Comfy.GroupSelectedNodes.Padding'
)
group.addNodes(Object.values(app.canvas.selected_nodes), padding)
app.canvas.graph.add(group)
}
})
]) as HTMLDivElement

Expand Down
1 change: 1 addition & 0 deletions src/scripts/ui/menu/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export class ComfyAppMenu {
app
})
)

this.actionsGroup = new ComfyButtonGroup(
new ComfyButton({
icon: 'refresh',
Expand Down
11 changes: 11 additions & 0 deletions src/stores/settingStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,17 @@ export const useSettingStore = defineStore('setting', {
type: 'hidden',
defaultValue: ['.safetensors', '.sft']
})

app.ui.settings.addSetting({
id: 'Comfy.GroupSelectedNodes.Padding',
name: 'Group selected nodes padding',
type: 'slider',
defaultValue: 10,
attrs: {
min: 0,
max: 100
}
})
},

set<K extends keyof Settings>(key: K, value: Settings[K]) {
Expand Down