fix(undo-redo): use consistent target state for toggle redo

The redo logic for BATCH_TOGGLE_ENABLED and BATCH_TOGGLE_LOCKED was
incorrectly computing each block's new state as !previousStates[blockId].
However, the store's batchToggleEnabled/batchToggleLocked set ALL blocks
to the SAME target state based on the first block's previous state.

Now redo computes targetState = !previousStates[firstBlockId] and applies
it to all blocks, matching the store's behavior.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
waleed
2026-01-31 21:01:55 -08:00
parent 3fbcfc662c
commit 52d9f31621

View File

@@ -1447,10 +1447,12 @@ export function useUndoRedo() {
userId,
})
// Use setBlockEnabled to directly set to toggled state
// Redo sets to !previousStates (the state after the original toggle)
// Compute target state the same way batchToggleEnabled does:
// use !firstBlock.enabled, where firstBlock is blockIds[0]
const firstBlockId = blockIds[0]
const targetEnabled = !previousStates[firstBlockId]
validBlockIds.forEach((blockId) => {
useWorkflowStore.getState().setBlockEnabled(blockId, !previousStates[blockId])
useWorkflowStore.getState().setBlockEnabled(blockId, targetEnabled)
})
break
}
@@ -1505,10 +1507,12 @@ export function useUndoRedo() {
userId,
})
// Use setBlockLocked to directly set to toggled state
// Redo sets to !previousStates (the state after the original toggle)
// Compute target state the same way batchToggleLocked does:
// use !firstBlock.locked, where firstBlock is blockIds[0]
const firstBlockId = blockIds[0]
const targetLocked = !previousStates[firstBlockId]
validBlockIds.forEach((blockId) => {
useWorkflowStore.getState().setBlockLocked(blockId, !previousStates[blockId])
useWorkflowStore.getState().setBlockLocked(blockId, targetLocked)
})
break
}