mirror of
https://github.com/scratchfoundation/scratch-paint.git
synced 2024-12-22 21:42:30 -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 () {
|
||||
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 (
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue