vakata/jstree — Issue #113: Feature request: undo/redo plugin
Author: paulhickman
Created: 2011-10-29 23:11:33+00:00
State: open

I would live to see an undo/redo plugin added if this is feasible.

My idea is to maintain two stacks - an undo stack and a redo stack. Each stack frame contains an object with two fields - a description of the operation (e.g. Move node or Delete Subtree) and the data necessary to undo/redo it which would be considered internal.

Whenever an operation is performed that affects the tree structure, push to a frame to the undo stack describing it, and clear all frames from the redo stack. Discard the oldest undo stack frame if it is full.

When an undo operation is performed, pop the undo stack and use the frame popped to restore the tree. Push the frame to the redo stack.

When an redo operation is performed, pop the redo stack and use the information to redo the operation against the tree. Push the frame to the undo stack.

Provide methods:

undo(n) - undo the last n actions
redo(n) - redo the next n actions

getUndoStack() - retrieve the undo stack
getRedoStack() - retrieve the redo stack

Retrieving the stack will allow a simple user interface with undo/redo buttons to enable/disable the buttons, or a complex user interface to provide a drop-down list of the number of actions to undo/redo a-la MS word.

Configuration options:

maximumUndoDepth - the largest number of actions that can be pushed to the undo stack before the deepest is discarded.

includeExpansion - toggle whether opening/closing nodes are actions that are recorded to the stack, or if it is only actions that change the tree structure.