Report an issue
Class

CKEDITOR.plugins.undo.UndoManager

class private

Main logic for the Redo/Undo feature.

Filtering

Properties

  • limit : Number

    readonly

    The maximum number of snapshots in the stack. Configurable via CKEDITOR.config.undoStackSize.

  • locked : Object

    readonly

    When the locked property is not null, the undo manager is locked, so operations like save or update are forbidden.

    The manager can be locked and unlocked by the lock and unlock methods, respectively.

    Defaults to null

  • previousKeyGroup : Number

    since 4.4.4 readonly

    Contains the previously processed key group, based on keyGroups. -1 means an unknown group.

    Defaults to -1

  • strokesLimit : Number

    since 4.4.5 readonly

    The maximum number of characters typed/deleted in one undo step.

    Defaults to 25

  • strokesRecorded : Array

    since 4.4.4

    An array storing the number of key presses, count in a row. Use keyGroups members as index.

    Note: The keystroke count will be reset after reaching the limit of characters per snapshot.

    Defaults to [0, 0]

Static properties

  • keyGroups : Object

    since 4.4.5 readonly static

    Key groups identifier mapping. Used for accessing members in strokesRecorded.

    • FUNCTIONAL – identifier for the Backspace / Delete key.
    • PRINTABLE – identifier for printable keys.

    Example usage:

    undoManager.strokesRecorded[ undoManager.keyGroups.FUNCTIONAL ];
    

    Defaults to {PRINTABLE: 0, FUNCTIONAL: 1}

  • navigationKeyCodes : Object

    since 4.4.5 readonly static

    Codes for navigation keys like Arrows, Page Up/Down, etc. Used by the isNavigationKey method.

    Defaults to {37: 1, 38: 1, 39: 1, 40: 1, 36: 1, 35: 1, 33: 1, 34: 1}

Methods

  • constructor( editor ) → UndoManager

    Creates an UndoManager class instance.

    Parameters

    editor : editor

    Returns

    UndoManager
  • getNextImage( isUndo ) → Image

    Gets the closest available image.

    Parameters

    isUndo : Boolean

    If true, it will return the previous image.

    Returns

    Image

    Next image or null.

  • keyGroupChanged( keyCode ) → Boolean

    since 4.4.5

    Whether the new keyCode belongs to a different group than the previous one (previousKeyGroup).

    Parameters

    keyCode : Number

    Returns

    Boolean
  • lock( [ dontUpdate ], [ forceUpdate ] )

    since 4.0

    Locks the snapshot stack to prevent any save/update operations and when necessary, updates the tip of the snapshot stack with the DOM changes introduced during the locked period, after the unlock method is called.

    It is mainly used to ensure any DOM operations that should not be recorded (e.g. auto paragraphing) are not added to the stack.

    Note: For every lock call you must call unlock once to unlock the undo manager.

    Parameters

    [ dontUpdate ] : Boolean

    When set to true, the last snapshot will not be updated with current content and selection. By default, if undo manager was up to date when the lock started, the last snapshot will be updated to the current state when unlocking. This means that all changes done during the lock will be merged into the previous snapshot or the next one. Use this option to gain more control over this behavior. For example, it is possible to group changes done during the lock into a separate snapshot.

    [ forceUpdate ] : Boolean

    When set to true, the last snapshot will always be updated with the current content and selection regardless of the current state of the undo manager. When not set, the last snapshot will be updated only if the undo manager was up to date when locking. Additionally, this option makes it possible to lock the snapshot when the editor is not in the wysiwyg mode, because when it is passed, the snapshots will not need to be compared.

  • redo()

    Performs a redo operation on current index.

  • redoable() → Boolean

    Checks the current redo state.

    Returns

    Boolean

    Whether the document has a previous state to retrieve.

  • refreshState()

    Refreshes the state of the undo manager as well as the state of the undo and redo commands.

  • reset()

    Resets the undo stack.

  • resetType()

    Resets all typing variables.

    type

  • restoreImage( image )

    Sets editor content/selection to the one stored in image.

    Parameters

    image : Image
  • save( onContentOnly, image, [ autoFireChange ] )

    Saves a snapshot of the document image for later retrieval.

    Parameters

    onContentOnly : Boolean

    If set to true, the snapshot will be saved only if the content has changed.

    image : Image

    An optional image to save. If skipped, current editor will be used.

    [ autoFireChange ] : Boolean

    If set to false, will not trigger the CKEDITOR.editor.change event to editor.

    Defaults to true

  • type( keyCode, [ strokesPerSnapshotExceeded ] )

    Handles keystroke support for the undo manager. It is called on keyup event for keystrokes that can change the editor content.

    Parameters

    keyCode : Number

    The key code.

    [ strokesPerSnapshotExceeded ] : Boolean

    When set to true, the method will behave as if the strokes limit was exceeded regardless of the strokesRecorded value.

  • undo()

    Performs an undo operation on current index.

  • undoable() → Boolean

    Checks the current undo state.

    Returns

    Boolean

    Whether the document has a future state to restore.

  • unlock()

    since 4.0

    Unlocks the snapshot stack and checks to amend the last snapshot.

    See lock for more details.

  • update( [ newImage ] )

    Updates the last snapshot of the undo stack with the current editor content.

    Parameters

    [ newImage ] : Image

    The image which will replace the current one. If it is not set, it defaults to the image taken from the editor.

  • updateSelection( newSnapshot ) → Boolean

    since 4.4.4

    Amends the last snapshot and changes its selection (only in case when content is equal between these two).

    Parameters

    newSnapshot : Image

    New snapshot with new selection.

    Returns

    Boolean

    Returns true if selection was amended.

Static methods

  • getKeyGroup( keyCode ) → Number

    since 4.4.5 static

    Returns the group to which the passed keyCode belongs.

    Parameters

    keyCode : Number

    Returns

    Number
  • getOppositeKeyGroup( keyGroup ) → Number

    since 4.4.5 static

    Parameters

    keyGroup : Number

    Returns

    Number
  • ieFunctionalKeysBug( keyCode ) → Boolean

    since 4.4.5 static

    Whether we need to use a workaround for functional (Backspace, Delete) keys not firing the keypress event in Internet Explorer in this environment and for the specified keyCode.

    Parameters

    keyCode : Number

    Returns

    Boolean
  • isNavigationKey( keyCode ) → Boolean

    since 4.4.5 static

    Checks whether a key is one of navigation keys (Arrows, Page Up/Down, etc.). See also the navigationKeyCodes property.

    Parameters

    keyCode : Number

    Returns

    Boolean