VTT Markup Undo/Redo Design
I. Undoable Markup operations
VTT provides undo/redo for markup operations. Undoable and redoable operations include:
- Add: tag a selected (highlight) text by adding a new markup
- Change: change the tag (properties) for a selected markup
- Delete: delete a selected markup
- Join: join the selected markup with the next markup
- Override: override all markups on the highlight text
II. Java Classes
III. Undo Operations
The undo operation class performs the undo/redo basic operations of add/change/delete on markups.
- Undo operations:
- if not undoable (no UndoNode in undoNodes_ or index_ is -1)
- set undo.setEnable(false)
- beep
- else
- Get the current undoNode from undoNodes_ list
- reduce index_ (in UndoManager) by 1
- Update markups by undoNode
- Go through all undoBases in the undoNode
- Find the markup (index) from Markups_ list by the offset and length (unique) of current markup in UndoBase
- ADD:
- delete the added markup from markups_ list
- set markup select index = -1 (no select)
- Update text/markup style
- set text highlight to the deleted markup (update markup style again)
- CHANGE:
- set properties of prev markup to the selected markup on Markups_ list
- set markup select index to the changed markup
- Update text/markup style
- DELETE:
- add the deleted markup back to markups_ list
- set markup select index to the added markup
- Update text/markup style
- Update modeless dialogs: Markup and MarkupsDialog
- Redo operations:
- if not redoable (no UndoNode in undoNodes_ or index_ is at the end of the list)
- set redo.setEnable(false)
- beep
- else
- Get the next (current + 1) undoNode from undoNodes_ list
- increase index_ (in UndoManager) by 1
- Update markups by redoNode
- Go through all redoBases in the redoNode
- Find the markup (index) from Markups_ list by offset and length (unique) of current markup in RedoBase
- ADD:
- set markup select index to the markup to be added
- add the markup to markups_ list
- Update text/markup style
- CHANGE:
- set properties of prev markup to the selected markup on markups_ list
- set markup select index to the changed markup
- Update text/markup style
- DELETE:
- delete the selected markup from Markups_ list
- set markup select index to the added markup
- Update text/markup style
- Update modeless dialogs: Markup and MarkupsDialog