Flip History Strategy Guide

Handling a Simple Modification

This chapter shows to implement a simple undo, that is an undo step that relates to a single commit of the document.


Some common modifications of the document are one-shot. That is, the actual modification of the document, its commit and publication to the outside world happens once in a row.

Example of such modifications are :

The general idea of the modification is that they are punctual events, that is they don't span over time. An example of modification that does not fall in this category would be for example modification that comes from a mouse gesture, where the document is modified gradually as the gesture is performed.


The following code illustrates a modification of the document such as a menu item used to insert a track in a song.

Document document (Model::use (), 123456789UL, 'appl', 'gui ');
History <HistoryStoreMemory> history (document);
Song & song = document.root <Song> ();
song.tracks.emplace (song.tracks.end ());
auto tx = document.commit ();    (1)
history.add_undo_step (tx);      (2)
document.push ();                (3)
  1. In this case, the modification is simply a single commit
  2. Add this modification as an undo step
  3. Typically, the client of the library would advertise this document modification to the outside world at that moment

The next chapter, Handling a Gesture will show a strategy to use for undo/redo in the case of a gesture.