Skip to content

Commit

Permalink
Clear Redo stack when doing undoable UI event (surge-synthesizer#6078)
Browse files Browse the repository at this point in the history
So do do undo undo redo -> stack OK
do do undo newdo -> redostack clear

Addreses surge-synthesizer#694
  • Loading branch information
baconpaul authored Apr 23, 2022
1 parent 8f2956b commit 7d2c606
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/surge-xt/gui/UndoManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ struct UndoManagerImpl
SelfPushGuard(UndoManagerImpl *imp) : that(imp) { that->doPush = false; }
~SelfPushGuard() { that->doPush = true; }
};

bool clearRedoOnUndo{true};
struct DontClearRedoOnUndoGuard
{
UndoManagerImpl *that;
DontClearRedoOnUndoGuard(UndoManagerImpl *imp) : that(imp)
{
that->clearRedoOnUndo = false;
}
~DontClearRedoOnUndoGuard() { that->clearRedoOnUndo = true; }
};
struct CleanupGuard
{
UndoManagerImpl *that;
Expand Down Expand Up @@ -299,6 +310,10 @@ struct UndoManagerImpl
{
undoStack.emplace_back(r);
undoStackMem += actionSize(r);
if (clearRedoOnUndo)
{
clearRedo();
}
return;
}

Expand All @@ -307,6 +322,10 @@ struct UndoManagerImpl
{
undoStack.emplace_back(r);
undoStackMem += actionSize(r);
if (clearRedoOnUndo)
{
clearRedo();
}
}
else
{
Expand All @@ -321,10 +340,24 @@ struct UndoManagerImpl
{
undoStack.emplace_back(r);
undoStackMem += actionSize(r);
if (clearRedoOnUndo)
{
clearRedo();
}
}
}
}

void clearRedo()
{
for (auto &r : redoStack)
{
freeAction(r.action);
}
redoStack.clear();
redoStackMem = 0;
}

void pushRedo(const UndoAction &r)
{
if (!doPush)
Expand Down Expand Up @@ -616,6 +649,7 @@ struct UndoManagerImpl

bool undoRedoImpl(UndoManager::Target which)
{
auto dcroug = DontClearRedoOnUndoGuard(this);
auto *currStack = &undoStack;
auto *currStackMem = &undoStackMem;
if (which == UndoManager::REDO)
Expand Down

0 comments on commit 7d2c606

Please sign in to comment.