Rules for Undo?


I am currently implementing Undo in our application.

And I am wondering: are there any rules, or rather guidelines, how to group Undo actions together?

So this is actually not a JUCE question. It is more of a genera UI development question.

For example: In modern Text Editors, such as Visual Studio. When you type text there, it will not undo everything letter by letter. Instead it will group Undo actions into words, or maybe even undo a whole sentence at once.

My Application is an Audio application. So there is not much typing. But I still want to group actions together. E.g. if the user changes the same slider many times in a row, I would want to make it only one Undo action.

Are there any dissertations or tutorials, or similar, which give guidelines on how to determine, what actions should be grouped together? People must have been thinking about this before. :slight_smile:

One way would be to use timers. Another way would be to always group actions of the same type together. Both have pros and cons, I’d say. And maybe there are even other ways?

Note: I know how to group actions together in JUCE with the Undo Manager. So its not a programming questions. Its more a guidelines questions. About the logic behind Undo. And how to think about Undo. If that makes sense :slight_smile:



A nice pattern that @jules posted a while back, which I adopted, is to add a timer every tenth of a second, and if no mouse button is pressed, call beginNewTransaction();.

void timerCallback() override
    for (auto& source : Desktop::getInstance().getMouseSources())
        if (source.isDragging())


The empty transactions are automatically discarded.



Hi Daniel,
Thanks for the tip. Looks interesting.

Anyone else with good suggestions? :slight_smile: