mirror of
https://github.com/scratchfoundation/scratch-paint.git
synced 2025-01-09 14:12:13 -05:00
update stage on undo and redo
This commit is contained in:
parent
7523af09f0
commit
87eb78ad49
2 changed files with 12 additions and 9 deletions
|
@ -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 (
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue