How to make A/B button in plugin without reseting undo history with APVTS?

I’ve spent a lot of time on undo/redo (with the apvts undomanager). This stuff can go very deep. My recommendation is to first be completely clear on the high level expectation of the behavior you want.

When I click the A/B button, what is the expectation?

  1. Does it add an UndoableAction? Can I “undo” the compare? If so, then you’ll want to register a new transaction with the UndoManager and then use copyPropertiesFrom. For example, loading presets could work this way, treating the preset load as something that you can undo:
apvts.undoManager->beginNewTransaction ("Change Preset");
apvts.state.copyPropertiesFrom (otherState, undoable ? apvts.undoManager : nullptr);

I tend to call a function to do this with an undoable boolean as there are times I want to register an UndoableAction (preset load) and other times where I do not (setStateInformation).

I also had issues with the values not being set, so I actually then iterate over the tree and manually populate the values… unideal but it gets the job done.

  1. Does it rollback to compare with a prior state that’s in the undo history? In that case, could you just call undo X times?

  2. Does a “compare” completely ignore the UndoManager? In that case, what’s the expected behavior if I hit compare and then undo? This seems like it could have some edge case behavior that would be annoying to solve, but in theory can be solved the same way as #1, with undoable set to false.