I'm working on some electronics simulation software that manages projects that are organised in a tree structure: modules in modules in modules, etc... (For instance, the project may contain modules A and B, module A may contain module C and C may contain D and E, and so on.)

I would like to add an undo/redo feature to the program but I don't know if the undo/redo stacks should be on a per-module (per-node) basis (such that the changes can be undone independently) or on a project basis (such that holding Ctrl+Z will revert to initial save state if held long enough).

Will users find it confusing if it is on a per-module basis? Would they prefer it on the contrary? But can it cause chronology problems? Is there a consensus on such a problem? Which is better and why?

1 Answer 1


You should bind your undo-stack to a component and any change to the components model should lead to a command on the undo-stack. So if the user has access to multiple trees each tree should have unique undo-stack. If your model is displayed within on tree component you'll have one undo-stack.

I believe the user will be very much confused if you choose the per-module-undo within one tree component. It also does not answer well to this question: Why would you make an exception regarding the create-module, delete-module commands?

What adds up to the users confusion is that you'll also have something much more complex to implement.

  • "Why would you make an exception regarding the create-module, delete-module commands?" The entire project can be seen as a module: the "root module". Those changes could be added to the undo stack of the root. And if create-module or delete-module commands are executed within a module, then they could be added to the undo stack of the module currently being edited. Doesn't seem like there's an exception to me. Aug 4, 2022 at 20:01
  • "you'll also have something much more complex to implement" Actually, if the undo stack is on a project basis, I'll have to handle switching the view to where ever the action took place. For instance, we may be undoing a change in module A while editing module B. In this case, I'll want the user to see the change, so I'll have to switch the view back to module A before undoing the action. Seems like more work to me. Aug 4, 2022 at 20:04
  • I think you're right about the user being confused. A single undo and redo stack for the project seems better. I'll wait and see if anyone has more to say before moving forward though. Aug 4, 2022 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.