Class UndoManager
java.lang.Object
com.codename1.ui.editor.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.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidbreakRun()Breaks the current coalescing run so the next recorded insert starts a fresh undo unit.booleancanRedo()True when there is anything to redo.booleancanUndo()True when there is anything to undo.voidclear()Clears all recorded history.voidRecords a mutation for later undo.intredo(EditorDocument doc) Redoes the most recently undone mutation against the supplied document.intundo(EditorDocument doc) Undoes the most recent mutation against the supplied document.
-
Constructor Details
-
UndoManager
public UndoManager()
-
-
Method Details
-
record
Records a mutation for later undo. Clears the redo stack.
Parameters
-
start: the offset at which text was removed / inserted -
removed: the text that was removed (empty for a pure insert) -
inserted: 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
Undoes the most recent mutation against the supplied document.
Parameters
doc: the document to mutate
Returns
the caret offset after the undo, or -1 when there was nothing to undo
-
redo
Redoes the most recently undone mutation against the supplied document.
Parameters
doc: 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.
-