Fix legacy group color menu scoping

This commit is contained in:
dante01yoon
2026-03-09 15:23:41 +09:00
parent e6be6fd921
commit ed05e589bf
2 changed files with 66 additions and 1 deletions

View File

@@ -1,4 +1,5 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import type * as NodeColorPersistenceModule from '@/utils/nodeColorPersistence'
const settingStoreMock = vi.hoisted(() => ({
get: vi.fn(() => true)
@@ -13,7 +14,7 @@ vi.mock('@/platform/settings/settingStore', () => ({
}))
vi.mock('@/utils/nodeColorPersistence', async () => {
const actual = await vi.importActual<typeof import('@/utils/nodeColorPersistence')>(
const actual = await vi.importActual<typeof NodeColorPersistenceModule>(
'@/utils/nodeColorPersistence'
)
@@ -316,4 +317,64 @@ describe('LGraphCanvas.onMenuNodeColors', () => {
LiteGraph.ContextMenu = originalContextMenu
}
})
it('keeps legacy group color actions scoped to the clicked group', async () => {
const graph = {
beforeChange: vi.fn(),
afterChange: vi.fn()
}
const selectedNode = Object.assign(Object.create(LGraphNode.prototype), {
graph,
color: undefined,
bgcolor: undefined
}) as LGraphNode
const targetGroup = Object.assign(Object.create(LGraphGroup.prototype), {
graph,
color: undefined
}) as LGraphGroup
const canvas = {
selectedItems: new Set([selectedNode, targetGroup]),
setDirty: vi.fn()
}
LGraphCanvas.active_canvas = canvas as unknown as LGraphCanvas
let callback:
| ((value: { value?: unknown }) => void)
| undefined
const originalContextMenu = LiteGraph.ContextMenu
class MockContextMenu {
constructor(
_values: ReadonlyArray<{ content?: string } | string | null>,
options: { callback?: (value: { value?: unknown }) => void }
) {
callback = options.callback
}
}
LiteGraph.ContextMenu = MockContextMenu as unknown as typeof LiteGraph.ContextMenu
try {
LGraphCanvas.onMenuNodeColors(
{ content: 'Colors', value: null },
{} as never,
new MouseEvent('contextmenu'),
{} as ContextMenu<string | null>,
targetGroup
)
callback?.({
value: {
kind: 'custom-picker'
}
})
await Promise.resolve()
await Promise.resolve()
expect(targetGroup.color).toBe('#abcdef')
expect(selectedNode.bgcolor).toBeUndefined()
} finally {
LiteGraph.ContextMenu = originalContextMenu
}
})
})

View File

@@ -177,6 +177,10 @@ function isLegacyColorTarget(item: unknown): item is LegacyColorTarget {
}
function getLegacyColorTargets(target: LegacyColorTarget): LegacyColorTarget[] {
if (target instanceof LGraphGroup) {
return [target]
}
const selected = Array.from(LGraphCanvas.active_canvas.selectedItems).filter(
isLegacyColorTarget
)