Implemented undo/redo on cursor change.