Question Editor API Events
revisionHistoryState:change
Fires when the current state of the revision history changes.
You would want to be notified about this event firing because you might want manage the state of your own custom undo and redo buttons.
State changes are triggered by the following actions:
- The author clicks the undo or redo buttons.
- Calling
undo()
orredo()
methods. - The author changes any UI field (on input blur).
This event is fired twice per state change:
- The first event fires with both booleans set to
false
, to indicate both buttons should be disabled. - The second event fires with updated states once the first has completed. For example, after changing a field,
canUndo
will betrue
andcanRedo
will befalse
.
New state snapshots are typically very fast so both events will fire rapidly, but undo and redo operations can take some time. It is important to listen to these events and prevent or ignore further undo and redo commands until the current operation completes.
The on()
method can be used to listen to this event.
Examples
authorApp.on('revisionHistoryState:change', function (undoState) {
console.log('This code executes when the revision history has changed.');
console.log(undoState);
// When new text has been added, the first event's undoState will contain:
// { canUndo: false, canRedo: false }
// The second event's undoState will contain:
// { canUndo: true, canRedo: false }
});
Callback arguments
-
undoState object
Additional information about the current undo and redo state.
-
canUndo boolean
Indicates whether there is a previous state that Question Editor can be reverted to via the
undo()
method. -
canRedo boolean
Indicates whether there is a newer state that Question Editor can be restored to via
redo()
method.
-