public class UndoManager
- Object
- UndoManager
A compact undo / redo stack for the pure editors. Every mutation is recorded as a replacement of the
range
[start, start + removed.length) with inserted; the inverse simply swaps removed and
inserted. Consecutive single character insertions are coalesced into one undo unit so a burst of
typing undoes as a word rather than a keystroke at a time.Constructors
public UndoManager() |
Methods
public void record(int start, String removed, String inserted) | Records a mutation for later undo. |
public void breakRun() | Breaks the current coalescing run so the next recorded insert starts a fresh undo unit. |
public boolean canUndo() | True when there is anything to undo. |
public boolean canRedo() | True when there is anything to redo. |
public int undo(EditorDocument doc) | Undoes the most recent mutation against the supplied document. |
public int redo(EditorDocument doc) | Redoes the most recently undone mutation against the supplied document. |
public void clear() | Clears all recorded history. |
Inherited methods
Constructor details
UndoManager
public UndoManager()Method details
record
public void record(int start, String removed, String inserted)Records a mutation for later undo. Clears the redo stack.
Parameters
startint- the offset at which text was removed / inserted
removedString- the text that was removed (empty for a pure insert)
insertedString- the text that was inserted (empty for a pure delete)
breakRun
public void breakRun()Breaks the current coalescing run so the next recorded insert starts a fresh undo unit. Called on
caret jumps, selection changes and structural edits.
canUndo
public boolean canUndo()True when there is anything to undo.
canRedo
public boolean canRedo()True when there is anything to redo.
undo
public int undo(EditorDocument doc)Undoes the most recent mutation against the supplied document.
Parameters
docEditorDocument- the document to mutate
Returns
the caret offset after the undo, or -1 when there was nothing to undo
redo
public int redo(EditorDocument doc)Redoes the most recently undone mutation against the supplied document.
Parameters
docEditorDocument- the document to mutate
Returns
the caret offset after the redo, or -1 when there was nothing to redo
clear
public void clear()Clears all recorded history.