update stage on undo and redo

This commit is contained in:
DD 2017-10-05 18:24:52 -04:00
parent 7523af09f0
commit 87eb78ad49
2 changed files with 12 additions and 9 deletions

View file

@ -28,7 +28,7 @@ class PaintEditor extends React.Component {
componentWillUnmount () {
document.removeEventListener('keydown', this.props.onKeyPress);
}
handleUpdateSvg () {
handleUpdateSvg (skipSnapshot) {
// Hide bounding box
getGuideLayer().visible = false;
const bounds = paper.project.activeLayer.bounds;
@ -39,14 +39,16 @@ class PaintEditor extends React.Component {
}),
paper.project.view.center.x - bounds.x,
paper.project.view.center.y - bounds.y);
performSnapshot(this.props.undoSnapshot);
if (!skipSnapshot) {
performSnapshot(this.props.undoSnapshot);
}
getGuideLayer().visible = true;
}
handleUndo () {
performUndo(this.props.undoState, this.props.onUndo);
performUndo(this.props.undoState, this.props.onUndo, this.handleUpdateSvg);
}
handleRedo () {
performRedo(this.props.undoState, this.props.onRedo);
performRedo(this.props.undoState, this.props.onRedo, this.handleUpdateSvg);
}
render () {
return (

View file

@ -11,15 +11,16 @@ const performSnapshot = function (dispatchPerformSnapshot) {
// updateButtonVisibility();
};
const _restore = function (entry) {
const _restore = function (entry, onUpdateSvg) {
paper.project.clear();
paper.project.importJSON(entry.json);
paper.view.update();
onUpdateSvg(true /* skipSnapshot */);
};
const performUndo = function (undoState, dispatchPerformUndo) {
const performUndo = function (undoState, dispatchPerformUndo, onUpdateSvg) {
if (undoState.pointer > 0) {
_restore(undoState.stack[undoState.pointer - 1]);
_restore(undoState.stack[undoState.pointer - 1], onUpdateSvg);
dispatchPerformUndo();
// @todo enable/disable buttons
@ -28,9 +29,9 @@ const performUndo = function (undoState, dispatchPerformUndo) {
};
const performRedo = function (undoState, dispatchPerformRedo) {
const performRedo = function (undoState, dispatchPerformRedo, onUpdateSvg) {
if (undoState.pointer >= 0 && undoState.pointer < undoState.stack.length - 1) {
_restore(undoState.stack[undoState.pointer + 1]);
_restore(undoState.stack[undoState.pointer + 1], onUpdateSvg);
dispatchPerformRedo();
// @todo enable/disable buttons