Home

# Class goog.editor.plugins.UndoRedo

Encapsulates undo/redo logic using a custom undo stack (i.e. not browser built-in). Browser built-in undo stacks are too flaky (e.g. IE's gets clobbered on DOM modifications). Also, this allows interleaving non-editing commands into the undo stack via the UndoRedoManager.

extends goog.editor.Plugin

Instance Method Summary
| `clearHistory()` Clear the undo/redo stack.
| `disable(?goog.editor.Field fieldObject)` Disables this plugin for the specified, registered field object.
| `dispatchCommandValueChange_()` Dispatches the COMMAND_VALUE_CHANGE event on the editable field or the field manager, as appropriate. Note: Really, people using multi field mode should be listening directly to the undo-redo manager for events.

`disposeInternal()`

Unattach listeners from this object. Classes that extend EventTarget may need to override this method in order to remove references to DOM Elements and additional listeners, it should be something like this:

    MyClass.prototype.disposeInternal = function() {
    MyClass.superClass_.disposeInternal.call(this);
    // Dispose logic for MyClass
    };

| `enable(?goog.editor.Field fieldObject)` Enables this plugin for the specified, registered field object. A field object should only be enabled when it is loaded.

`execCommand(string command, <Any Type> var_args) ⇒ <Any Type>`

Handles execCommand. This default implementation handles dispatching BEFORECHANGE, CHANGE, and SELECTIONCHANGE events, and calls execCommandInternal to perform the actual command. Plugins that want to do their own event dispatching should override execCommand, otherwise it is preferred to only override execCommandInternal. This version of execCommand will only work for single field plugins. Multi-field plugins must override execCommand.

| `getCurrentEventTarget() ⇒ ?goog.editor.Field` This is so subclasses can deal with multifield undo-redo.
| `getCurrentFieldObject() ⇒ ?goog.editor.Field` This is so subclasses can deal with multifield undo-redo.
| `getCursorPosition_(?goog.editor.Field fieldObj) ⇒ ?goog.editor.plugins.UndoRedo.CursorPosition_` Returns the goog.editor.plugins.UndoRedo.CursorPosition_ for the current selection in the given Field.
| `getFieldObject(string fieldHashCode) ⇒ ?goog.editor.Field` This is so subclasses can deal with multifield undo-redo.
| `handleBeforeChange_(?goog.events.Event e)` Before the field changes, we want to save the state.
| `handleBlur_(?goog.events.Event e)` When the user blurs away, we need to save the state on that field.
| `handleDelayedChange_(?goog.events.Event e)` After some idle time, we want to save the state.
| `isEnabled(?goog.editor.Field fieldObject) ⇒ boolean` Returns whether this plugin is enabled for the field object.
| `isSupportedCommand(string command) ⇒ boolean` Whether the string corresponds to a command this plugin handles.
| `refreshCurrentState(?goog.editor.Field fieldObject)` Refreshes the current state of the editable field as maintained by undo-redo, without adding any undo-redo states to the stack.
| `registerFieldObject(?goog.editor.Field fieldObject)` Registers the field object for use with this plugin.
| `restoreState(?goog.editor.plugins.UndoRedo.UndoState_ state, string content, ?goog.editor.plugins.UndoRedo.CursorPosition_ cursorPosition)` Restores the state of the editable field.
| `setMaxUndoDepth(number depth)` Set the max undo stack depth (not the real memory usage).
| `setUndoRedoManager(?goog.editor.plugins.UndoRedoManager manager)` Set the undo-redo manager used by this plugin. Any state on a previous undo-redo manager is lost.

`unregisterFieldObject(?goog.editor.Field fieldObject)`

Unregisters and disables the fieldObject with this plugin. Thie does *not* clobber the undo stack for the fieldObject though. TODO(user): For the multifield version, we really should add a way to ignore undo actions on field's that have been made uneditable. This is probably as simple as skipping over entries in the undo stack that have a hashcode of an uneditable field.

| `updateCurrentState_(?goog.editor.Field fieldObj)` Helper method for saving state.

Static Method Summary
| `CursorPosition_(?goog.editor.Field field)` Stores the state of the selection in a way the survives DOM modifications that don't modify the user-interactable content (e.g. making something bold vs. typing a character). TODO(user): Completely get rid of this and use goog.dom.SavedCaretRange.
| `UndoState_(string fieldHashCode, string content, ?goog.editor.plugins.UndoRedo.CursorPosition_ cursorPosition, ?Function restore)` This object encapsulates the state of an editable field.