In many programs and web apps (stack exchange included) the program is able to backtrack what edits where made to the piece. My issue is similar: I want to be able to store a “timeline” of edits, where the user can go back and see what they typed at a specific time/when the typed certain words. What’s the standard way to do this? Also, in things like google docs and other programs, they automatically “group” actions together (Like if I delete something by hitting back space 5 times, it knows I was deleting one word), any ideas on how to do that to?
1
it’s actually pretty simple
for every action the user makes you create a Undoable with 3 key methods
-
undo() and redo(): for the actual undo and redo
-
combine(Undoable) which creates a new Undoable of the 2 combined if they can be combined (otherwise null)
the code will be something like:
public Undoable combine(Undoable other){ if(other instanceof UndoType){ return new UndoType(this.insertedString+((UndoType)other).insertedString),position); } return null; }
then when you add the Undoable to the undo stack you check with the combine
of the last undoable whether it can be combined