From 87eb78ad49e8e94888e9e3c3fd827a3eba5fec63 Mon Sep 17 00:00:00 2001 From: DD Date: Thu, 5 Oct 2017 18:24:52 -0400 Subject: [PATCH] update stage on undo and redo --- src/containers/paint-editor.jsx | 10 ++++++---- src/helper/undo.js | 11 ++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/containers/paint-editor.jsx b/src/containers/paint-editor.jsx index a7be96b2..c5154c0f 100644 --- a/src/containers/paint-editor.jsx +++ b/src/containers/paint-editor.jsx @@ -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 ( diff --git a/src/helper/undo.js b/src/helper/undo.js index 449aa834..45c13826 100644 --- a/src/helper/undo.js +++ b/src/helper/undo.js @@ -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