# Make undo management more flexible

**URL:** <https://forum.juce.com/t/make-undo-management-more-flexible/64283>\
**Category:** Feature Requests\
**Created:** [November 18, 2024, 5:08pm UTC](https://forum.juce.com/t/make-undo-management-more-flexible/64283 "2024-11-18T17:08:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![moritzsur](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@moritzsur](https://forum.juce.com/u/moritzsur)\
**Post date:** [November 18, 2024, 5:08pm UTC](https://forum.juce.com/t/make-undo-management-more-flexible/64283/1 "2024-11-18T17:08:58Z")

</div>

`juce::UndoManager` should be renamed to `UnitBasedUndoManager`.  
`UndoManager` should be a stripped down, pure abstract class. That class should be passed to other classes like `ValueTree`. The only method ever called on the UndoManagers in juce\_ValueTree.cpp is `perform`, so there is no reason to inject a concrete class into value trees, or is there?

---

<div class="post-metadata">

**Author:** ![anthony-nicholls](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/anthony-nicholls/32/1246_2.png) [@anthony-nicholls](https://forum.juce.com/u/anthony-nicholls)\
**Post date:** [November 18, 2024, 5:26pm UTC](https://forum.juce.com/t/make-undo-management-more-flexible/64283/2 "2024-11-18T17:26:35Z")

</div>

You would still need to pass a pointer to the instance of the `UndoManager` that actually performs the action. Is there a specific issue you’re facing?

---

<div class="post-metadata">

**Author:** ![moritzsur](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@moritzsur](https://forum.juce.com/u/moritzsur)\
**Post date:** [November 18, 2024, 5:55pm UTC](https://forum.juce.com/t/make-undo-management-more-flexible/64283/3 "2024-11-18T17:55:59Z")

</div>

Yes but then I can supply my own subclass of UndoManager, the current version has no virtual methods.

I need some custom behaviour to send out ARA content change notifications based on the actions performed. I would also add an UndoManagerListener to my custom class, for more in-depth notifications.

---

<div class="post-metadata">

**Author:** ![ImJimmi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/imjimmi/32/10843_2.png) [@ImJimmi](https://forum.juce.com/u/ImJimmi)\
**Post date:** [November 18, 2024, 6:01pm UTC](https://forum.juce.com/t/make-undo-management-more-flexible/64283/4 "2024-11-18T18:01:06Z")

</div>

A custom undo manager would also allow you to filter commands - e.g. to ignore value changes during a gesture, only storing the final value, or to only record changes for particular properties.

---

<div class="post-metadata">

**Author:** ![moritzsur](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@moritzsur](https://forum.juce.com/u/moritzsur)\
**Post date:** [November 18, 2024, 6:09pm UTC](https://forum.juce.com/t/make-undo-management-more-flexible/64283/5 "2024-11-18T18:09:58Z")

</div>

To be more specific I would handle listening with a callback like this

```auto
/**
* @param lastAction the last action performed. 
* Owned by MyCustomUndoManager and only guaranteed to be valid during the callback.
*/
UndoManagerListener::actionPerformed(ActionType type, UndoableAction* lastAction)
{
}

```

Where action type could be `normal`, `undo` or `redo`

---

<div class="post-metadata">

**Author:** ![Rincewind](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rincewind/32/10645_2.png) [@Rincewind](https://forum.juce.com/u/Rincewind)\
**Post date:** [November 19, 2024, 6:50am UTC](https://forum.juce.com/t/make-undo-management-more-flexible/64283/6 "2024-11-19T06:50:26Z")

</div>

This should already be working as the current manager tries to merge actions based on a virtual method inside action I believe.

---

<div class="post-metadata">

**Author:** ![hugoderwolf](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/hugoderwolf/32/14039_2.png) [@hugoderwolf](https://forum.juce.com/u/hugoderwolf)\
**Post date:** [November 19, 2024, 7:46am UTC](https://forum.juce.com/t/make-undo-management-more-flexible/64283/7 "2024-11-19T07:46:03Z")

</div>

Yes, but it doesn’t do so when multiple parameters are changed at once (say with an XY type of control). In that case you’ll end up with an awful lot of units.

I’d love to see an abstraction layer for the UndoManager, making customizations and extensions possible. I stumbled upon the current implementation a few times already!

---

<div class="post-metadata">

**Author:** ![Rincewind](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rincewind/32/10645_2.png) [@Rincewind](https://forum.juce.com/u/Rincewind)\
**Post date:** [November 24, 2026, 9:52am UTC](https://forum.juce.com/t/make-undo-management-more-flexible/64283/8 "2026-11-24T09:52:28Z")

</div>

I want to revisit this topic, as I just faced an issue, where I’d like to extend the behaviour:

In my application, that is handling audio unit hosting, posting the creation of an audio unit comes with a significant size of the undo-able action. Once I hit undo on the “audio unit create” or “audio unit remove”, the audio unit is essentially only still living because the undo manager, that might be a good few MB or even more. This is great for the first couple of undo-steps, as the user might remove the audio unit on accident and then hitting undo is really fast, as the audio unit still exist and everything is still loaded.

However, if the undo action is moved down in history the first couple steps, I’d like to clear the audio unit from the undo action to save memory but still have it in the history just in case.
