synchronized void executed ( RTEditText editor , Operation op ) { Stack < Operation > undoStack = getUndoStack ( editor ) ; Stack < Operation > redoStack = getRedoStack ( editor ) ; // if operations are executed in a quick succession we "merge" them to have but one // -> saves memory and makes more sense from a user perspective (each key stroke an undo? -> no way) while ( ! undoStack . empty ( ) && op . canMerge ( undoStack . peek ( ) ) ) { Operation previousOp = undoStack . pop ( ) ; op . merge ( previousOp ) ; } push ( op , undoStack ) ; redoStack . clear ( ) ; }
Call this when an operation is performed to add it to the undo stack .