revisionHistoryState.change - Events - Question Editor API

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() or redo() 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 be true and canRedo will be false.

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.

Was this article helpful?

Did you arrive here by accident? If so, learn more about Learnosity.