mirror of
https://github.com/scratchfoundation/scratch-paint.git
synced 2024-12-22 21:42:30 -05:00
add missing file
This commit is contained in:
parent
345a43e127
commit
7523af09f0
1 changed files with 45 additions and 0 deletions
45
src/helper/undo.js
Normal file
45
src/helper/undo.js
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
// undo functionality
|
||||||
|
// modifed from https://github.com/memononen/stylii
|
||||||
|
import paper from 'paper';
|
||||||
|
|
||||||
|
const performSnapshot = function (dispatchPerformSnapshot) {
|
||||||
|
dispatchPerformSnapshot({
|
||||||
|
json: paper.project.exportJSON({asString: false})
|
||||||
|
});
|
||||||
|
|
||||||
|
// @todo enable/disable buttons
|
||||||
|
// updateButtonVisibility();
|
||||||
|
};
|
||||||
|
|
||||||
|
const _restore = function (entry) {
|
||||||
|
paper.project.clear();
|
||||||
|
paper.project.importJSON(entry.json);
|
||||||
|
paper.view.update();
|
||||||
|
};
|
||||||
|
|
||||||
|
const performUndo = function (undoState, dispatchPerformUndo) {
|
||||||
|
if (undoState.pointer > 0) {
|
||||||
|
_restore(undoState.stack[undoState.pointer - 1]);
|
||||||
|
dispatchPerformUndo();
|
||||||
|
|
||||||
|
// @todo enable/disable buttons
|
||||||
|
// updateButtonVisibility();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const performRedo = function (undoState, dispatchPerformRedo) {
|
||||||
|
if (undoState.pointer >= 0 && undoState.pointer < undoState.stack.length - 1) {
|
||||||
|
_restore(undoState.stack[undoState.pointer + 1]);
|
||||||
|
dispatchPerformRedo();
|
||||||
|
|
||||||
|
// @todo enable/disable buttons
|
||||||
|
// updateButtonVisibility();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export {
|
||||||
|
performSnapshot,
|
||||||
|
performUndo,
|
||||||
|
performRedo
|
||||||
|
};
|
Loading…
Reference in a new issue