Sure, computers are powerful tools that allow us to create, edit, and share various types of content. However, it can also be a source of frustrations and even horror especially when we lose our work or made a mistake that ruins the creation. We may make mistakes or change our minds about what we want to do. That’s where so many productivity and creativity programs have the Undo feature, which lets us easily reverse our last action. Whether we accidentally delete some text, move an image, or apply a wrong filter, we can use Undo to quickly fix our error and get back to the previous state before the error. Undo is an immensely useful feature but who invented it and how does it work? In this post, I’ll give you a very quick introduction.
The Dawn of Undo
Come to think of it, we have been using “undo” long before computers by erasing our work or covering it up with paint etc. After typewriters were invented, the “white-out” became a common tool in every office. The ability to undo an operation on a computer was independently invented multiple times in response to how people used computers. The File Retrieval and Editing System, developed starting in 1968 at Brown University, is reported to be the first computer-based system to have had an “undo” feature. Warren Teitelman developed a Programmer’s Assistant as part of BBN-LISP with an Undo function by 1971. The Xerox PARC Bravo text editor had an Undo command in 1974.
The programmers at the Xerox PARC research center assigned the keyboard shortcut Ctrl-Z to the undo command, which became a crucial feature of text editors and word processors in the personal computer era. Larry Tesler of Xerox PARC began working at Apple Computer in 1980, where he and Bill Atkinson advocated for the presence of an undo command as a standard fixture on the Apple Lisa.
Early versions of Undo was only able to undo one operation, and there was no Redo. The concept of multiple undos, where every command, tool application, or menu item initiated during a work session is recorded and compiled on a sequential list of history states that can be accessed at any time, was introduced with the development of image editing software programs like Adobe Photoshop and Corel PaintShop Pro. Those programs enabled users to access any moment in the workflow to make corrections, and erasures. However, the exact date of the invention of multiple undos is unclear but certainly after the single undo feature becanme a standard in most applications, which was around the early 1980s.
Today all editing software supports multiple Undo and Redo feature.
How is multiple UNDO implemented?
The implementation of the multiple undo feature vary depending on the specific requirements of the application. It’s often implemented using design patterns like the Command pattern or the Memento pattern.
In the Command pattern, each action in the application is encapsulated as an object (a command). These commands are stored in a list or stack, allowing the application to perform undo operations by traversing this list in the reverse order and executing an undo operation for each command.
The Memento pattern involves saving the state of an object at a given point in time and being able to restore that object to its saved state. This can be used to implement multiple undos by saving a memento every time a change is made, and then restoring the mementos when the undo operation is performed. This is like a time machine.
In some applications such as Visual Studio, linked undo functionality is provided across multiple designers. This suggests that a linked data structure are used in those cases.
The exact implementation details depend on the specific requirements of the application. A linked list or stack or list of objects or states can be used in implementating the multiple undo feature.
Sample Demonstrations in Python
Below are just two small programs I wrote in Python to demonstrate how to implement a simple single Undo feature using Stack and then Linked List. In practice these days however, most applications that offer Undo/Redo features utilize proven, sophisticated pre-built Undo Engines built by other developers/parties and just plug that into their own applications saving the time and effort required to build the feature from ground-up.
Take a look at the example codes below and while they’re simple implementations, they should give you a pretty clear picture of the mechanism work. Click on to run it and the output will show in the window to its right. There is user-inputs in these demos…the inputs are hard-coded to simulate different states and inputs by the user.
Undo implementation using Stack:
Undo implementation using Linked List:
Hope you enjoyed this post!
Interested in creating programmable, cool electronic gadgets? Give my newest book on Arduino a try: Hello Arduino!