From 568be0c44cf090aba6ec0449e429ffecb27a0a85 Mon Sep 17 00:00:00 2001 From: AustinMroz Date: Thu, 11 Sep 2025 00:50:26 -0700 Subject: [PATCH] When toggling selected, align state (#5482) Previously, when toggling the mode of multiple nodes, each node would have its state individually toggled. Now it enables mode if any node is not currently set to that mode and only disables if all already match. --- src/composables/canvas/useSelectedLiteGraphItems.ts | 6 ++++-- .../composables/canvas/useSelectedLiteGraphItems.test.ts | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/composables/canvas/useSelectedLiteGraphItems.ts b/src/composables/canvas/useSelectedLiteGraphItems.ts index 0400bc833..369d2cdc9 100644 --- a/src/composables/canvas/useSelectedLiteGraphItems.ts +++ b/src/composables/canvas/useSelectedLiteGraphItems.ts @@ -123,12 +123,14 @@ export function useSelectedLiteGraphItems() { for (const i in selectedNodes) { selectedNodeArray.push(selectedNodes[i]) } + const allNodesMatch = !selectedNodeArray.some( + (selectedNode) => selectedNode.mode !== mode + ) + const newModeForSelectedNode = allNodesMatch ? LGraphEventMode.ALWAYS : mode // Process each selected node independently to determine its target state and apply to children selectedNodeArray.forEach((selectedNode) => { // Apply standard toggle logic to the selected node itself - const newModeForSelectedNode = - selectedNode.mode === mode ? LGraphEventMode.ALWAYS : mode selectedNode.mode = newModeForSelectedNode diff --git a/tests-ui/tests/composables/canvas/useSelectedLiteGraphItems.test.ts b/tests-ui/tests/composables/canvas/useSelectedLiteGraphItems.test.ts index 1774af294..11673efc8 100644 --- a/tests-ui/tests/composables/canvas/useSelectedLiteGraphItems.test.ts +++ b/tests-ui/tests/composables/canvas/useSelectedLiteGraphItems.test.ts @@ -237,9 +237,9 @@ describe('useSelectedLiteGraphItems', () => { toggleSelectedNodesMode(LGraphEventMode.NEVER) // node1 should change from ALWAYS to NEVER - // node2 should change from NEVER to ALWAYS (since it was already NEVER) + // node2 should stay NEVER (since a selected node exists which is not NEVER) expect(node1.mode).toBe(LGraphEventMode.NEVER) - expect(node2.mode).toBe(LGraphEventMode.ALWAYS) + expect(node2.mode).toBe(LGraphEventMode.NEVER) }) it('toggleSelectedNodesMode should set mode to ALWAYS when already in target mode', () => {