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 () { componentWillUnmount () {
document.removeEventListener('keydown', this.props.onKeyPress); document.removeEventListener('keydown', this.props.onKeyPress);
} }
handleUpdateSvg () { handleUpdateSvg (skipSnapshot) {
// Hide bounding box // Hide bounding box
getGuideLayer().visible = false; getGuideLayer().visible = false;
const bounds = paper.project.activeLayer.bounds; 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.x - bounds.x,
paper.project.view.center.y - bounds.y); paper.project.view.center.y - bounds.y);
if (!skipSnapshot) {
performSnapshot(this.props.undoSnapshot); performSnapshot(this.props.undoSnapshot);
}
getGuideLayer().visible = true; getGuideLayer().visible = true;
} }
handleUndo () { handleUndo () {
performUndo(this.props.undoState, this.props.onUndo); performUndo(this.props.undoState, this.props.onUndo, this.handleUpdateSvg);
} }
handleRedo () { handleRedo () {
performRedo(this.props.undoState, this.props.onRedo); performRedo(this.props.undoState, this.props.onRedo, this.handleUpdateSvg);
} }
render () { render () {
return ( return (

View file

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