Looking at the git commit log, I think the current behaviour is intentional. undoCurrentTransactionOnly restores the “previous” redo history when called, which is useful if you need to abort a new change and retain the previous redo stack. For example, the following code will work:
juce::ValueTree tree("data");
juce::UndoManager undo;
tree.setProperty("T", 4, nullptr);
undo.beginNewTransaction("set T to 1");
tree.setProperty("T", 1, &undo);
undo.beginNewTransaction("set T to 2");
tree.setProperty("T", 2, &undo);
undo.beginNewTransaction("set T to 3");
tree.setProperty("T", 3, &undo);
undo.undo();
jassert((int)tree.getProperty("T") == 2);
undo.undo();
jassert((int)tree.getProperty("T") == 1);
tree.setProperty("T", 5, &undo);
undo.undoCurrentTransactionOnly(); // Oops, didn't mean to set T to 5!
undo.redo();
jassert((int)tree.getProperty("T") == 2); // We still have the old redo history
undo.redo();
jassert((int)tree.getProperty("T") == 3);
It looks like undoCurrentTransactionOnly is supposed to irrevocably cancel any action that is currently in progress. Changing this behaviour may introduce subtle bugs in existing programs, so I don’t think this behaviour should be changed at this point.
I will overcome it calling this on my mouseDrag(), preventing it undoes other action that wasn’t the initial one:
if (um.getNumActionsInCurrentTransaction())
{
String name = um.getCurrentTransactionName();
um.undo();
um.beginNewTransaction(name);
}
btw, FR, I wish there was a way to discard lastest actions from a transaction instead. So I could do an initial action “A” in mouseDown(), and do some repetitive actions “B” in mouseDrag() deleting only the last one, then when undo(), “B” and “A” would be in the same transaction.