mirror of
https://github.com/scratchfoundation/scratch-paint.git
synced 2024-12-22 13:32:28 -05:00
call undo
This commit is contained in:
parent
8baf731328
commit
28464b237b
25 changed files with 243 additions and 97 deletions
|
@ -58,11 +58,13 @@ class PaintEditorComponent extends React.Component {
|
||||||
<div className={styles.buttonGroup}>
|
<div className={styles.buttonGroup}>
|
||||||
<button
|
<button
|
||||||
className={styles.button}
|
className={styles.button}
|
||||||
|
onClick={this.props.onUndo}
|
||||||
>
|
>
|
||||||
Undo
|
Undo
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
className={styles.button}
|
className={styles.button}
|
||||||
|
onClick={this.props.onRedo}
|
||||||
>
|
>
|
||||||
Redo
|
Redo
|
||||||
</button>
|
</button>
|
||||||
|
@ -154,6 +156,8 @@ class PaintEditorComponent extends React.Component {
|
||||||
|
|
||||||
PaintEditorComponent.propTypes = {
|
PaintEditorComponent.propTypes = {
|
||||||
intl: intlShape,
|
intl: intlShape,
|
||||||
|
onRedo: PropTypes.func.isRequired,
|
||||||
|
onUndo: PropTypes.func.isRequired,
|
||||||
onUpdateSvg: PropTypes.func.isRequired,
|
onUpdateSvg: PropTypes.func.isRequired,
|
||||||
rotationCenterX: PropTypes.number,
|
rotationCenterX: PropTypes.number,
|
||||||
rotationCenterY: PropTypes.number,
|
rotationCenterY: PropTypes.number,
|
||||||
|
|
|
@ -4,6 +4,7 @@ import BroadBrushHelper from './broad-brush-helper';
|
||||||
import SegmentBrushHelper from './segment-brush-helper';
|
import SegmentBrushHelper from './segment-brush-helper';
|
||||||
import {MIXED, styleCursorPreview} from '../../helper/style-path';
|
import {MIXED, styleCursorPreview} from '../../helper/style-path';
|
||||||
import {clearSelection} from '../../helper/selection';
|
import {clearSelection} from '../../helper/selection';
|
||||||
|
import {performSnapshot} from '../../helper/undo';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shared code for the brush and eraser mode. Adds functions on the paper tool object
|
* Shared code for the brush and eraser mode. Adds functions on the paper tool object
|
||||||
|
@ -29,11 +30,12 @@ class Blobbiness {
|
||||||
* @param {function} updateCallback call when the drawing has changed to let listeners know
|
* @param {function} updateCallback call when the drawing has changed to let listeners know
|
||||||
* @param {function} clearSelectedItems Callback to clear the set of selected items in the Redux state
|
* @param {function} clearSelectedItems Callback to clear the set of selected items in the Redux state
|
||||||
*/
|
*/
|
||||||
constructor (updateCallback, clearSelectedItems) {
|
constructor (updateCallback, clearSelectedItems, undoSnapshot) {
|
||||||
this.broadBrushHelper = new BroadBrushHelper();
|
this.broadBrushHelper = new BroadBrushHelper();
|
||||||
this.segmentBrushHelper = new SegmentBrushHelper();
|
this.segmentBrushHelper = new SegmentBrushHelper();
|
||||||
this.updateCallback = updateCallback;
|
this.updateCallback = updateCallback;
|
||||||
this.clearSelectedItems = clearSelectedItems;
|
this.clearSelectedItems = clearSelectedItems;
|
||||||
|
this.undoSnapshot = undoSnapshot;
|
||||||
|
|
||||||
// The following are stored to check whether these have changed and the cursor preview needs to be redrawn.
|
// The following are stored to check whether these have changed and the cursor preview needs to be redrawn.
|
||||||
this.strokeColor = null;
|
this.strokeColor = null;
|
||||||
|
@ -144,6 +146,7 @@ class Blobbiness {
|
||||||
|
|
||||||
blob.cursorPreview.visible = false;
|
blob.cursorPreview.visible = false;
|
||||||
blob.updateCallback();
|
blob.updateCallback();
|
||||||
|
performSnapshot(blob.undoSnapshot);
|
||||||
blob.cursorPreview.visible = true;
|
blob.cursorPreview.visible = true;
|
||||||
blob.cursorPreview.bringToFront();
|
blob.cursorPreview.bringToFront();
|
||||||
blob.cursorPreview.position = event.point;
|
blob.cursorPreview.position = event.point;
|
||||||
|
@ -234,8 +237,6 @@ class Blobbiness {
|
||||||
paths.splice(i, 1);
|
paths.splice(i, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: Add back undo
|
|
||||||
// pg.undo.snapshot('broadbrush');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mergeEraser (lastPath) {
|
mergeEraser (lastPath) {
|
||||||
|
@ -284,8 +285,6 @@ class Blobbiness {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lastPath.remove();
|
lastPath.remove();
|
||||||
// TODO add back undo
|
|
||||||
// pg.undo.snapshot('eraser');
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Erase
|
// Erase
|
||||||
|
@ -358,8 +357,6 @@ class Blobbiness {
|
||||||
items[i].remove();
|
items[i].remove();
|
||||||
}
|
}
|
||||||
lastPath.remove();
|
lastPath.remove();
|
||||||
// TODO: Add back undo handling
|
|
||||||
// pg.undo.snapshot('eraser');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
colorMatch (existingPath, addedPath) {
|
colorMatch (existingPath, addedPath) {
|
||||||
|
|
|
@ -4,10 +4,13 @@ import {connect} from 'react-redux';
|
||||||
import bindAll from 'lodash.bindall';
|
import bindAll from 'lodash.bindall';
|
||||||
import Modes from '../modes/modes';
|
import Modes from '../modes/modes';
|
||||||
import Blobbiness from './blob/blob';
|
import Blobbiness from './blob/blob';
|
||||||
|
|
||||||
import {changeBrushSize} from '../reducers/brush-mode';
|
import {changeBrushSize} from '../reducers/brush-mode';
|
||||||
import {changeMode} from '../reducers/modes';
|
import {changeMode} from '../reducers/modes';
|
||||||
import {clearSelectedItems} from '../reducers/selected-items';
|
import {clearSelectedItems} from '../reducers/selected-items';
|
||||||
|
import {undoSnapshot} from '../reducers/undo';
|
||||||
import {clearSelection} from '../helper/selection';
|
import {clearSelection} from '../helper/selection';
|
||||||
|
|
||||||
import BrushModeComponent from '../components/brush-mode.jsx';
|
import BrushModeComponent from '../components/brush-mode.jsx';
|
||||||
|
|
||||||
class BrushMode extends React.Component {
|
class BrushMode extends React.Component {
|
||||||
|
@ -18,7 +21,8 @@ class BrushMode extends React.Component {
|
||||||
'deactivateTool',
|
'deactivateTool',
|
||||||
'onScroll'
|
'onScroll'
|
||||||
]);
|
]);
|
||||||
this.blob = new Blobbiness(this.props.onUpdateSvg, this.props.clearSelectedItems);
|
this.blob = new Blobbiness(
|
||||||
|
this.props.onUpdateSvg, this.props.clearSelectedItems, this.props.undoSnapshot);
|
||||||
}
|
}
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
if (this.props.isBrushModeActive) {
|
if (this.props.isBrushModeActive) {
|
||||||
|
@ -87,7 +91,8 @@ BrushMode.propTypes = {
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
handleMouseDown: PropTypes.func.isRequired,
|
handleMouseDown: PropTypes.func.isRequired,
|
||||||
isBrushModeActive: PropTypes.bool.isRequired,
|
isBrushModeActive: PropTypes.bool.isRequired,
|
||||||
onUpdateSvg: PropTypes.func.isRequired
|
onUpdateSvg: PropTypes.func.isRequired,
|
||||||
|
undoSnapshot: PropTypes.func.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
const mapStateToProps = state => ({
|
const mapStateToProps = state => ({
|
||||||
|
@ -104,6 +109,9 @@ const mapDispatchToProps = dispatch => ({
|
||||||
},
|
},
|
||||||
handleMouseDown: () => {
|
handleMouseDown: () => {
|
||||||
dispatch(changeMode(Modes.BRUSH));
|
dispatch(changeMode(Modes.BRUSH));
|
||||||
|
},
|
||||||
|
undoSnapshot: snapshot => {
|
||||||
|
dispatch(undoSnapshot(snapshot));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import Modes from '../modes/modes';
|
||||||
import Blobbiness from './blob/blob';
|
import Blobbiness from './blob/blob';
|
||||||
import {changeBrushSize} from '../reducers/eraser-mode';
|
import {changeBrushSize} from '../reducers/eraser-mode';
|
||||||
import {clearSelectedItems} from '../reducers/selected-items';
|
import {clearSelectedItems} from '../reducers/selected-items';
|
||||||
|
import {undoSnapshot} from '../reducers/undo';
|
||||||
import EraserModeComponent from '../components/eraser-mode.jsx';
|
import EraserModeComponent from '../components/eraser-mode.jsx';
|
||||||
import {changeMode} from '../reducers/modes';
|
import {changeMode} from '../reducers/modes';
|
||||||
|
|
||||||
|
@ -17,7 +18,8 @@ class EraserMode extends React.Component {
|
||||||
'deactivateTool',
|
'deactivateTool',
|
||||||
'onScroll'
|
'onScroll'
|
||||||
]);
|
]);
|
||||||
this.blob = new Blobbiness(this.props.onUpdateSvg, this.props.clearSelectedItems);
|
this.blob = new Blobbiness(
|
||||||
|
this.props.onUpdateSvg, this.props.clearSelectedItems, this.props.undoSnapshot);
|
||||||
}
|
}
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
if (this.props.isEraserModeActive) {
|
if (this.props.isEraserModeActive) {
|
||||||
|
@ -72,7 +74,8 @@ EraserMode.propTypes = {
|
||||||
}),
|
}),
|
||||||
handleMouseDown: PropTypes.func.isRequired,
|
handleMouseDown: PropTypes.func.isRequired,
|
||||||
isEraserModeActive: PropTypes.bool.isRequired,
|
isEraserModeActive: PropTypes.bool.isRequired,
|
||||||
onUpdateSvg: PropTypes.func.isRequired
|
onUpdateSvg: PropTypes.func.isRequired,
|
||||||
|
undoSnapshot: PropTypes.func.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
const mapStateToProps = state => ({
|
const mapStateToProps = state => ({
|
||||||
|
@ -88,6 +91,9 @@ const mapDispatchToProps = dispatch => ({
|
||||||
},
|
},
|
||||||
handleMouseDown: () => {
|
handleMouseDown: () => {
|
||||||
dispatch(changeMode(Modes.ERASER));
|
dispatch(changeMode(Modes.ERASER));
|
||||||
|
},
|
||||||
|
undoSnapshot: snapshot => {
|
||||||
|
dispatch(undoSnapshot(snapshot));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,16 @@ import {connect} from 'react-redux';
|
||||||
import {changeFillColor} from '../reducers/fill-color';
|
import {changeFillColor} from '../reducers/fill-color';
|
||||||
import FillColorIndicatorComponent from '../components/fill-color-indicator.jsx';
|
import FillColorIndicatorComponent from '../components/fill-color-indicator.jsx';
|
||||||
import {applyFillColorToSelection} from '../helper/style-path';
|
import {applyFillColorToSelection} from '../helper/style-path';
|
||||||
|
import {performSnapshot} from '../helper/undo';
|
||||||
|
import {undoSnapshot} from '../reducers/undo';
|
||||||
|
|
||||||
const mapStateToProps = state => ({
|
const mapStateToProps = state => ({
|
||||||
fillColor: state.scratchPaint.color.fillColor
|
fillColor: state.scratchPaint.color.fillColor
|
||||||
});
|
});
|
||||||
const mapDispatchToProps = dispatch => ({
|
const mapDispatchToProps = dispatch => ({
|
||||||
onChangeFillColor: fillColor => {
|
onChangeFillColor: fillColor => {
|
||||||
applyFillColorToSelection(fillColor);
|
applyFillColorToSelection(fillColor, undoSnapshot);
|
||||||
|
performSnapshot(snapshot => dispatch(undoSnapshot(snapshot)));
|
||||||
dispatch(changeFillColor(fillColor));
|
dispatch(changeFillColor(fillColor));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import paper from 'paper';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import {connect} from 'react-redux';
|
import {connect} from 'react-redux';
|
||||||
|
@ -6,10 +7,13 @@ import Modes from '../modes/modes';
|
||||||
import {changeStrokeWidth} from '../reducers/stroke-width';
|
import {changeStrokeWidth} from '../reducers/stroke-width';
|
||||||
import {clearSelection, getSelectedLeafItems} from '../helper/selection';
|
import {clearSelection, getSelectedLeafItems} from '../helper/selection';
|
||||||
import {MIXED} from '../helper/style-path';
|
import {MIXED} from '../helper/style-path';
|
||||||
import {clearSelectedItems, setSelectedItems} from '../reducers/selected-items';
|
|
||||||
import LineModeComponent from '../components/line-mode.jsx';
|
|
||||||
import {changeMode} from '../reducers/modes';
|
import {changeMode} from '../reducers/modes';
|
||||||
import paper from 'paper';
|
import {changeStrokeWidth} from '../reducers/stroke-width';
|
||||||
|
import {clearSelectedItems, setSelectedItems} from '../reducers/selected-items';
|
||||||
|
import {performSnapshot} from '../helper/undo';
|
||||||
|
import {undoSnapshot} from '../reducers/undo';
|
||||||
|
|
||||||
|
import LineModeComponent from '../components/line-mode.jsx';
|
||||||
|
|
||||||
class LineMode extends React.Component {
|
class LineMode extends React.Component {
|
||||||
static get SNAP_TOLERANCE () {
|
static get SNAP_TOLERANCE () {
|
||||||
|
@ -209,10 +213,9 @@ class LineMode extends React.Component {
|
||||||
this.props.onUpdateSvg();
|
this.props.onUpdateSvg();
|
||||||
this.props.setSelectedItems();
|
this.props.setSelectedItems();
|
||||||
|
|
||||||
// TODO add back undo
|
if (this.path) {
|
||||||
// if (this.path) {
|
performSnapshot(this.props.undoSnapshot);
|
||||||
// pg.undo.snapshot('line');
|
}
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
toleranceSquared () {
|
toleranceSquared () {
|
||||||
return Math.pow(LineMode.SNAP_TOLERANCE / paper.view.zoom, 2);
|
return Math.pow(LineMode.SNAP_TOLERANCE / paper.view.zoom, 2);
|
||||||
|
@ -284,7 +287,8 @@ LineMode.propTypes = {
|
||||||
handleMouseDown: PropTypes.func.isRequired,
|
handleMouseDown: PropTypes.func.isRequired,
|
||||||
isLineModeActive: PropTypes.bool.isRequired,
|
isLineModeActive: PropTypes.bool.isRequired,
|
||||||
onUpdateSvg: PropTypes.func.isRequired,
|
onUpdateSvg: PropTypes.func.isRequired,
|
||||||
setSelectedItems: PropTypes.func.isRequired
|
setSelectedItems: PropTypes.func.isRequired,
|
||||||
|
undoSnapshot: PropTypes.func.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
const mapStateToProps = state => ({
|
const mapStateToProps = state => ({
|
||||||
|
@ -303,6 +307,9 @@ const mapDispatchToProps = dispatch => ({
|
||||||
},
|
},
|
||||||
handleMouseDown: () => {
|
handleMouseDown: () => {
|
||||||
dispatch(changeMode(Modes.LINE));
|
dispatch(changeMode(Modes.LINE));
|
||||||
|
},
|
||||||
|
undoSnapshot: snapshot => {
|
||||||
|
dispatch(undoSnapshot(snapshot));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PaintEditorComponent from '../components/paint-editor.jsx';
|
import PaintEditorComponent from '../components/paint-editor.jsx';
|
||||||
|
|
||||||
import {changeMode} from '../reducers/modes';
|
import {changeMode} from '../reducers/modes';
|
||||||
|
import {undo, redo} from '../reducers/undo';
|
||||||
|
|
||||||
import {getGuideLayer} from '../helper/layer';
|
import {getGuideLayer} from '../helper/layer';
|
||||||
|
import {performUndo, performRedo} from '../helper/undo';
|
||||||
|
|
||||||
import Modes from '../modes/modes';
|
import Modes from '../modes/modes';
|
||||||
import {connect} from 'react-redux';
|
import {connect} from 'react-redux';
|
||||||
import bindAll from 'lodash.bindall';
|
import bindAll from 'lodash.bindall';
|
||||||
|
@ -12,7 +17,9 @@ class PaintEditor extends React.Component {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
super(props);
|
super(props);
|
||||||
bindAll(this, [
|
bindAll(this, [
|
||||||
'handleUpdateSvg'
|
'handleUpdateSvg',
|
||||||
|
'handleUndo',
|
||||||
|
'handleRedo'
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
|
@ -34,12 +41,20 @@ class PaintEditor extends React.Component {
|
||||||
paper.project.view.center.y - bounds.y);
|
paper.project.view.center.y - bounds.y);
|
||||||
getGuideLayer().visible = true;
|
getGuideLayer().visible = true;
|
||||||
}
|
}
|
||||||
|
handleUndo () {
|
||||||
|
performUndo(this.props.undoState, this.props.onUndo);
|
||||||
|
}
|
||||||
|
handleRedo () {
|
||||||
|
performRedo(this.props.undoState, this.props.onRedo);
|
||||||
|
}
|
||||||
render () {
|
render () {
|
||||||
return (
|
return (
|
||||||
<PaintEditorComponent
|
<PaintEditorComponent
|
||||||
rotationCenterX={this.props.rotationCenterX}
|
rotationCenterX={this.props.rotationCenterX}
|
||||||
rotationCenterY={this.props.rotationCenterY}
|
rotationCenterY={this.props.rotationCenterY}
|
||||||
svg={this.props.svg}
|
svg={this.props.svg}
|
||||||
|
onRedo={this.handleRedo}
|
||||||
|
onUndo={this.handleUndo}
|
||||||
onUpdateSvg={this.handleUpdateSvg}
|
onUpdateSvg={this.handleUpdateSvg}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
@ -48,12 +63,21 @@ class PaintEditor extends React.Component {
|
||||||
|
|
||||||
PaintEditor.propTypes = {
|
PaintEditor.propTypes = {
|
||||||
onKeyPress: PropTypes.func.isRequired,
|
onKeyPress: PropTypes.func.isRequired,
|
||||||
|
onRedo: PropTypes.func.isRequired,
|
||||||
|
onUndo: PropTypes.func.isRequired,
|
||||||
onUpdateSvg: PropTypes.func.isRequired,
|
onUpdateSvg: PropTypes.func.isRequired,
|
||||||
rotationCenterX: PropTypes.number,
|
rotationCenterX: PropTypes.number,
|
||||||
rotationCenterY: PropTypes.number,
|
rotationCenterY: PropTypes.number,
|
||||||
svg: PropTypes.string
|
svg: PropTypes.string,
|
||||||
|
undoState: PropTypes.shape({
|
||||||
|
stack: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||||
|
pointer: PropTypes.number.isRequired
|
||||||
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const mapStateToProps = state => ({
|
||||||
|
undoState: state.scratchPaint.undo
|
||||||
|
});
|
||||||
const mapDispatchToProps = dispatch => ({
|
const mapDispatchToProps = dispatch => ({
|
||||||
onKeyPress: event => {
|
onKeyPress: event => {
|
||||||
if (event.key === 'e') {
|
if (event.key === 'e') {
|
||||||
|
@ -65,10 +89,16 @@ const mapDispatchToProps = dispatch => ({
|
||||||
} else if (event.key === 's') {
|
} else if (event.key === 's') {
|
||||||
dispatch(changeMode(Modes.SELECT));
|
dispatch(changeMode(Modes.SELECT));
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
onUndo: () => {
|
||||||
|
dispatch(undo());
|
||||||
|
},
|
||||||
|
onRedo: () => {
|
||||||
|
dispatch(redo());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(
|
export default connect(
|
||||||
null,
|
mapStateToProps,
|
||||||
mapDispatchToProps
|
mapDispatchToProps
|
||||||
)(PaintEditor);
|
)(PaintEditor);
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
import bindAll from 'lodash.bindall';
|
import bindAll from 'lodash.bindall';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import {connect} from 'react-redux';
|
||||||
import paper from 'paper';
|
import paper from 'paper';
|
||||||
|
|
||||||
|
import {performSnapshot} from '../helper/undo';
|
||||||
|
import {undoSnapshot} from '../reducers/undo';
|
||||||
|
|
||||||
import styles from './paper-canvas.css';
|
import styles from './paper-canvas.css';
|
||||||
|
|
||||||
class PaperCanvas extends React.Component {
|
class PaperCanvas extends React.Component {
|
||||||
|
@ -20,6 +24,7 @@ class PaperCanvas extends React.Component {
|
||||||
if (this.props.svg) {
|
if (this.props.svg) {
|
||||||
this.importSvg(this.props.svg, this.props.rotationCenterX, this.props.rotationCenterY);
|
this.importSvg(this.props.svg, this.props.rotationCenterX, this.props.rotationCenterY);
|
||||||
}
|
}
|
||||||
|
performSnapshot(this.props.undoSnapshot);
|
||||||
}
|
}
|
||||||
componentWillReceiveProps (newProps) {
|
componentWillReceiveProps (newProps) {
|
||||||
paper.project.activeLayer.removeChildren();
|
paper.project.activeLayer.removeChildren();
|
||||||
|
@ -85,7 +90,16 @@ PaperCanvas.propTypes = {
|
||||||
canvasRef: PropTypes.func,
|
canvasRef: PropTypes.func,
|
||||||
rotationCenterX: PropTypes.number,
|
rotationCenterX: PropTypes.number,
|
||||||
rotationCenterY: PropTypes.number,
|
rotationCenterY: PropTypes.number,
|
||||||
svg: PropTypes.string
|
svg: PropTypes.string,
|
||||||
|
undoSnapshot: PropTypes.func.isRequired
|
||||||
};
|
};
|
||||||
|
const mapDispatchToProps = dispatch => ({
|
||||||
|
undoSnapshot: snapshot => {
|
||||||
|
dispatch(undoSnapshot(snapshot));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
export default PaperCanvas;
|
export default connect(
|
||||||
|
null,
|
||||||
|
mapDispatchToProps
|
||||||
|
)(PaperCanvas);
|
||||||
|
|
|
@ -8,6 +8,7 @@ import {changeMode} from '../reducers/modes';
|
||||||
import {clearHoveredItem, setHoveredItem} from '../reducers/hover';
|
import {clearHoveredItem, setHoveredItem} from '../reducers/hover';
|
||||||
import {clearSelectedItems, setSelectedItems} from '../reducers/selected-items';
|
import {clearSelectedItems, setSelectedItems} from '../reducers/selected-items';
|
||||||
import {getSelectedLeafItems} from '../helper/selection';
|
import {getSelectedLeafItems} from '../helper/selection';
|
||||||
|
import {undoSnapshot} from '../reducers/undo';
|
||||||
|
|
||||||
import ReshapeTool from '../helper/selection-tools/reshape-tool';
|
import ReshapeTool from '../helper/selection-tools/reshape-tool';
|
||||||
import ReshapeModeComponent from '../components/reshape-mode.jsx';
|
import ReshapeModeComponent from '../components/reshape-mode.jsx';
|
||||||
|
@ -45,7 +46,9 @@ class ReshapeMode extends React.Component {
|
||||||
this.props.clearHoveredItem,
|
this.props.clearHoveredItem,
|
||||||
this.props.setSelectedItems,
|
this.props.setSelectedItems,
|
||||||
this.props.clearSelectedItems,
|
this.props.clearSelectedItems,
|
||||||
this.props.onUpdateSvg);
|
this.props.onUpdateSvg,
|
||||||
|
this.props.undoSnapshot
|
||||||
|
);
|
||||||
this.tool.setPrevHoveredItemId(this.props.hoveredItemId);
|
this.tool.setPrevHoveredItemId(this.props.hoveredItemId);
|
||||||
this.tool.activate();
|
this.tool.activate();
|
||||||
}
|
}
|
||||||
|
@ -70,7 +73,8 @@ ReshapeMode.propTypes = {
|
||||||
isReshapeModeActive: PropTypes.bool.isRequired,
|
isReshapeModeActive: PropTypes.bool.isRequired,
|
||||||
onUpdateSvg: PropTypes.func.isRequired,
|
onUpdateSvg: PropTypes.func.isRequired,
|
||||||
setHoveredItem: PropTypes.func.isRequired,
|
setHoveredItem: PropTypes.func.isRequired,
|
||||||
setSelectedItems: PropTypes.func.isRequired
|
setSelectedItems: PropTypes.func.isRequired,
|
||||||
|
undoSnapshot: PropTypes.func.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
const mapStateToProps = state => ({
|
const mapStateToProps = state => ({
|
||||||
|
@ -92,6 +96,9 @@ const mapDispatchToProps = dispatch => ({
|
||||||
},
|
},
|
||||||
handleMouseDown: () => {
|
handleMouseDown: () => {
|
||||||
dispatch(changeMode(Modes.RESHAPE));
|
dispatch(changeMode(Modes.RESHAPE));
|
||||||
|
},
|
||||||
|
undoSnapshot: snapshot => {
|
||||||
|
dispatch(undoSnapshot(snapshot));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import Modes from '../modes/modes';
|
||||||
import {changeMode} from '../reducers/modes';
|
import {changeMode} from '../reducers/modes';
|
||||||
import {clearHoveredItem, setHoveredItem} from '../reducers/hover';
|
import {clearHoveredItem, setHoveredItem} from '../reducers/hover';
|
||||||
import {clearSelectedItems, setSelectedItems} from '../reducers/selected-items';
|
import {clearSelectedItems, setSelectedItems} from '../reducers/selected-items';
|
||||||
|
import {undoSnapshot} from '../reducers/undo';
|
||||||
|
|
||||||
import {getSelectedLeafItems} from '../helper/selection';
|
import {getSelectedLeafItems} from '../helper/selection';
|
||||||
import SelectTool from '../helper/selection-tools/select-tool';
|
import SelectTool from '../helper/selection-tools/select-tool';
|
||||||
|
@ -45,7 +46,9 @@ class SelectMode extends React.Component {
|
||||||
this.props.clearHoveredItem,
|
this.props.clearHoveredItem,
|
||||||
this.props.setSelectedItems,
|
this.props.setSelectedItems,
|
||||||
this.props.clearSelectedItems,
|
this.props.clearSelectedItems,
|
||||||
this.props.onUpdateSvg);
|
this.props.onUpdateSvg,
|
||||||
|
this.props.undoSnapshot
|
||||||
|
);
|
||||||
this.tool.activate();
|
this.tool.activate();
|
||||||
}
|
}
|
||||||
deactivateTool () {
|
deactivateTool () {
|
||||||
|
@ -68,7 +71,8 @@ SelectMode.propTypes = {
|
||||||
isSelectModeActive: PropTypes.bool.isRequired,
|
isSelectModeActive: PropTypes.bool.isRequired,
|
||||||
onUpdateSvg: PropTypes.func.isRequired,
|
onUpdateSvg: PropTypes.func.isRequired,
|
||||||
setHoveredItem: PropTypes.func.isRequired,
|
setHoveredItem: PropTypes.func.isRequired,
|
||||||
setSelectedItems: PropTypes.func.isRequired
|
setSelectedItems: PropTypes.func.isRequired,
|
||||||
|
undoSnapshot: PropTypes.func.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
const mapStateToProps = state => ({
|
const mapStateToProps = state => ({
|
||||||
|
@ -90,6 +94,9 @@ const mapDispatchToProps = dispatch => ({
|
||||||
},
|
},
|
||||||
handleMouseDown: () => {
|
handleMouseDown: () => {
|
||||||
dispatch(changeMode(Modes.SELECT));
|
dispatch(changeMode(Modes.SELECT));
|
||||||
|
},
|
||||||
|
undoSnapshot: snapshot => {
|
||||||
|
dispatch(undoSnapshot(snapshot));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,16 @@ import {connect} from 'react-redux';
|
||||||
import {changeStrokeColor} from '../reducers/stroke-color';
|
import {changeStrokeColor} from '../reducers/stroke-color';
|
||||||
import StrokeColorIndicatorComponent from '../components/stroke-color-indicator.jsx';
|
import StrokeColorIndicatorComponent from '../components/stroke-color-indicator.jsx';
|
||||||
import {applyStrokeColorToSelection} from '../helper/style-path';
|
import {applyStrokeColorToSelection} from '../helper/style-path';
|
||||||
|
import {performSnapshot} from '../helper/undo';
|
||||||
|
import {undoSnapshot} from '../reducers/undo';
|
||||||
|
|
||||||
const mapStateToProps = state => ({
|
const mapStateToProps = state => ({
|
||||||
strokeColor: state.scratchPaint.color.strokeColor
|
strokeColor: state.scratchPaint.color.strokeColor
|
||||||
});
|
});
|
||||||
const mapDispatchToProps = dispatch => ({
|
const mapDispatchToProps = dispatch => ({
|
||||||
onChangeStrokeColor: strokeColor => {
|
onChangeStrokeColor: strokeColor => {
|
||||||
applyStrokeColorToSelection(strokeColor);
|
applyStrokeColorToSelection(strokeColor, undoSnapshot);
|
||||||
|
performSnapshot(snapshot => dispatch(undoSnapshot(snapshot)));
|
||||||
dispatch(changeStrokeColor(strokeColor));
|
dispatch(changeStrokeColor(strokeColor));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,13 +2,16 @@ import {connect} from 'react-redux';
|
||||||
import {changeStrokeWidth} from '../reducers/stroke-width';
|
import {changeStrokeWidth} from '../reducers/stroke-width';
|
||||||
import StrokeWidthIndicatorComponent from '../components/stroke-width-indicator.jsx';
|
import StrokeWidthIndicatorComponent from '../components/stroke-width-indicator.jsx';
|
||||||
import {applyStrokeWidthToSelection} from '../helper/style-path';
|
import {applyStrokeWidthToSelection} from '../helper/style-path';
|
||||||
|
import {performSnapshot} from '../helper/undo';
|
||||||
|
import {undoSnapshot} from '../reducers/undo';
|
||||||
|
|
||||||
const mapStateToProps = state => ({
|
const mapStateToProps = state => ({
|
||||||
strokeWidth: state.scratchPaint.color.strokeWidth
|
strokeWidth: state.scratchPaint.color.strokeWidth
|
||||||
});
|
});
|
||||||
const mapDispatchToProps = dispatch => ({
|
const mapDispatchToProps = dispatch => ({
|
||||||
onChangeStrokeWidth: strokeWidth => {
|
onChangeStrokeWidth: strokeWidth => {
|
||||||
applyStrokeWidthToSelection(strokeWidth);
|
applyStrokeWidthToSelection(strokeWidth, undoSnapshot);
|
||||||
|
performSnapshot(snapshot => dispatch(undoSnapshot(snapshot)));
|
||||||
dispatch(changeStrokeWidth(strokeWidth));
|
dispatch(changeStrokeWidth(strokeWidth));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -36,16 +36,16 @@ class BoundingBoxTool {
|
||||||
* @param {function} clearSelectedItems Callback to clear the set of selected items in the Redux state
|
* @param {function} clearSelectedItems Callback to clear the set of selected items in the Redux state
|
||||||
* @param {!function} onUpdateSvg A callback to call when the image visibly changes
|
* @param {!function} onUpdateSvg A callback to call when the image visibly changes
|
||||||
*/
|
*/
|
||||||
constructor (setSelectedItems, clearSelectedItems, onUpdateSvg) {
|
constructor (setSelectedItems, clearSelectedItems, onUpdateSvg, undoSnapshot) {
|
||||||
this.onUpdateSvg = onUpdateSvg;
|
this.onUpdateSvg = onUpdateSvg;
|
||||||
this.mode = null;
|
this.mode = null;
|
||||||
this.boundsPath = null;
|
this.boundsPath = null;
|
||||||
this.boundsScaleHandles = [];
|
this.boundsScaleHandles = [];
|
||||||
this.boundsRotHandles = [];
|
this.boundsRotHandles = [];
|
||||||
this._modeMap = {};
|
this._modeMap = {};
|
||||||
this._modeMap[Modes.SCALE] = new ScaleTool(onUpdateSvg);
|
this._modeMap[Modes.SCALE] = new ScaleTool(onUpdateSvg, undoSnapshot);
|
||||||
this._modeMap[Modes.ROTATE] = new RotateTool(onUpdateSvg);
|
this._modeMap[Modes.ROTATE] = new RotateTool(onUpdateSvg, undoSnapshot);
|
||||||
this._modeMap[Modes.MOVE] = new MoveTool(setSelectedItems, clearSelectedItems, onUpdateSvg);
|
this._modeMap[Modes.MOVE] = new MoveTool(setSelectedItems, clearSelectedItems, onUpdateSvg, undoSnapshot);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import {clearSelection, getSelectedLeafItems} from '../selection';
|
import {clearSelection, getSelectedLeafItems} from '../selection';
|
||||||
|
import {performSnapshot} from '../undo';
|
||||||
|
|
||||||
/** Sub tool of the Reshape tool for moving handles, which adjust bezier curves. */
|
/** Sub tool of the Reshape tool for moving handles, which adjust bezier curves. */
|
||||||
class HandleTool {
|
class HandleTool {
|
||||||
|
@ -7,11 +8,13 @@ class HandleTool {
|
||||||
* @param {function} clearSelectedItems Callback to clear the set of selected items in the Redux state
|
* @param {function} clearSelectedItems Callback to clear the set of selected items in the Redux state
|
||||||
* @param {!function} onUpdateSvg A callback to call when the image visibly changes
|
* @param {!function} onUpdateSvg A callback to call when the image visibly changes
|
||||||
*/
|
*/
|
||||||
constructor (setSelectedItems, clearSelectedItems, onUpdateSvg) {
|
constructor (setSelectedItems, clearSelectedItems, onUpdateSvg, undoSnapshot) {
|
||||||
this.hitType = null;
|
this.hitType = null;
|
||||||
this.setSelectedItems = setSelectedItems;
|
this.setSelectedItems = setSelectedItems;
|
||||||
this.clearSelectedItems = clearSelectedItems;
|
this.clearSelectedItems = clearSelectedItems;
|
||||||
this.onUpdateSvg = onUpdateSvg;
|
this.onUpdateSvg = onUpdateSvg;
|
||||||
|
this.undoSnapshot = undoSnapshot;
|
||||||
|
this.selectedItems = [];
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @param {!object} hitProperties Describes the mouse event
|
* @param {!object} hitProperties Describes the mouse event
|
||||||
|
@ -28,9 +31,9 @@ class HandleTool {
|
||||||
this.hitType = hitProperties.hitResult.type;
|
this.hitType = hitProperties.hitResult.type;
|
||||||
}
|
}
|
||||||
onMouseDrag (event) {
|
onMouseDrag (event) {
|
||||||
const selectedItems = getSelectedLeafItems();
|
this.selectedItems = getSelectedLeafItems();
|
||||||
|
|
||||||
for (const item of selectedItems) {
|
for (const item of this.selectedItems) {
|
||||||
for (const seg of item.segments) {
|
for (const seg of item.segments) {
|
||||||
// add the point of the segment before the drag started
|
// add the point of the segment before the drag started
|
||||||
// for later use in the snap calculation
|
// for later use in the snap calculation
|
||||||
|
@ -66,8 +69,24 @@ class HandleTool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onMouseUp () {
|
onMouseUp () {
|
||||||
// @todo add back undo
|
// resetting the items and segments origin points for the next usage
|
||||||
this.onUpdateSvg();
|
let moved = false;
|
||||||
|
for (const item of this.selectedItems) {
|
||||||
|
if (!item.segments) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (const seg of item.segments) {
|
||||||
|
if (seg.origPoint && !seg.equals(seg.origPoint)) {
|
||||||
|
moved = true;
|
||||||
|
}
|
||||||
|
seg.origPoint = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (moved) {
|
||||||
|
performSnapshot(this.undoSnapshot);
|
||||||
|
this.onUpdateSvg();
|
||||||
|
}
|
||||||
|
this.selectedItems = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ import {isGroup} from '../group';
|
||||||
import {isCompoundPathItem, getRootItem} from '../item';
|
import {isCompoundPathItem, getRootItem} from '../item';
|
||||||
import {snapDeltaToAngle} from '../math';
|
import {snapDeltaToAngle} from '../math';
|
||||||
import {clearSelection, cloneSelection, getSelectedLeafItems, setItemSelection} from '../selection';
|
import {clearSelection, cloneSelection, getSelectedLeafItems, setItemSelection} from '../selection';
|
||||||
|
import {performSnapshot} from '../undo';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tool to handle dragging an item to reposition it in a selection mode.
|
* Tool to handle dragging an item to reposition it in a selection mode.
|
||||||
|
@ -12,11 +13,12 @@ class MoveTool {
|
||||||
* @param {function} clearSelectedItems Callback to clear the set of selected items in the Redux state
|
* @param {function} clearSelectedItems Callback to clear the set of selected items in the Redux state
|
||||||
* @param {!function} onUpdateSvg A callback to call when the image visibly changes
|
* @param {!function} onUpdateSvg A callback to call when the image visibly changes
|
||||||
*/
|
*/
|
||||||
constructor (setSelectedItems, clearSelectedItems, onUpdateSvg) {
|
constructor (setSelectedItems, clearSelectedItems, onUpdateSvg, undoSnapshot) {
|
||||||
this.setSelectedItems = setSelectedItems;
|
this.setSelectedItems = setSelectedItems;
|
||||||
this.clearSelectedItems = clearSelectedItems;
|
this.clearSelectedItems = clearSelectedItems;
|
||||||
this.selectedItems = null;
|
this.selectedItems = null;
|
||||||
this.onUpdateSvg = onUpdateSvg;
|
this.onUpdateSvg = onUpdateSvg;
|
||||||
|
this.undoSnapshot = undoSnapshot;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -51,7 +53,7 @@ class MoveTool {
|
||||||
}
|
}
|
||||||
this._select(item, true, hitProperties.subselect);
|
this._select(item, true, hitProperties.subselect);
|
||||||
}
|
}
|
||||||
if (hitProperties.clone) cloneSelection(hitProperties.subselect);
|
if (hitProperties.clone) cloneSelection(hitProperties.subselect, this.undoSnapshot);
|
||||||
this.selectedItems = getSelectedLeafItems();
|
this.selectedItems = getSelectedLeafItems();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -94,15 +96,20 @@ class MoveTool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onMouseUp () {
|
onMouseUp () {
|
||||||
|
let moved = false;
|
||||||
// resetting the items origin point for the next usage
|
// resetting the items origin point for the next usage
|
||||||
for (const item of this.selectedItems) {
|
for (const item of this.selectedItems) {
|
||||||
|
if (item.data.origPos && !item.position.equals(item.data.origPos)) {
|
||||||
|
moved = true;
|
||||||
|
}
|
||||||
item.data.origPos = null;
|
item.data.origPos = null;
|
||||||
}
|
}
|
||||||
this.selectedItems = null;
|
this.selectedItems = null;
|
||||||
|
|
||||||
// @todo add back undo
|
if (moved) {
|
||||||
// pg.undo.snapshot('moveSelection');
|
performSnapshot(this.undoSnapshot);
|
||||||
this.onUpdateSvg();
|
this.onUpdateSvg();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import paper from 'paper';
|
import paper from 'paper';
|
||||||
import {snapDeltaToAngle} from '../math';
|
import {snapDeltaToAngle} from '../math';
|
||||||
import {clearSelection, getSelectedLeafItems} from '../selection';
|
import {clearSelection, getSelectedLeafItems} from '../selection';
|
||||||
|
import {performSnapshot} from '../undo';
|
||||||
|
|
||||||
/** Subtool of ReshapeTool for moving control points. */
|
/** Subtool of ReshapeTool for moving control points. */
|
||||||
class PointTool {
|
class PointTool {
|
||||||
|
@ -9,7 +10,7 @@ class PointTool {
|
||||||
* @param {function} clearSelectedItems Callback to clear the set of selected items in the Redux state
|
* @param {function} clearSelectedItems Callback to clear the set of selected items in the Redux state
|
||||||
* @param {!function} onUpdateSvg A callback to call when the image visibly changes
|
* @param {!function} onUpdateSvg A callback to call when the image visibly changes
|
||||||
*/
|
*/
|
||||||
constructor (setSelectedItems, clearSelectedItems, onUpdateSvg) {
|
constructor (setSelectedItems, clearSelectedItems, onUpdateSvg, undoSnapshot) {
|
||||||
/**
|
/**
|
||||||
* Deselection often does not happen until mouse up. If the mouse is dragged before
|
* Deselection often does not happen until mouse up. If the mouse is dragged before
|
||||||
* mouse up, deselection is cancelled. This variable keeps track of which paper.Item to deselect.
|
* mouse up, deselection is cancelled. This variable keeps track of which paper.Item to deselect.
|
||||||
|
@ -29,6 +30,7 @@ class PointTool {
|
||||||
this.setSelectedItems = setSelectedItems;
|
this.setSelectedItems = setSelectedItems;
|
||||||
this.clearSelectedItems = clearSelectedItems;
|
this.clearSelectedItems = clearSelectedItems;
|
||||||
this.onUpdateSvg = onUpdateSvg;
|
this.onUpdateSvg = onUpdateSvg;
|
||||||
|
this.undoSnapshot = undoSnapshot;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -166,11 +168,15 @@ class PointTool {
|
||||||
}
|
}
|
||||||
onMouseUp () {
|
onMouseUp () {
|
||||||
// resetting the items and segments origin points for the next usage
|
// resetting the items and segments origin points for the next usage
|
||||||
|
let moved = false;
|
||||||
for (const item of this.selectedItems) {
|
for (const item of this.selectedItems) {
|
||||||
if (!item.segments) {
|
if (!item.segments) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (const seg of item.segments) {
|
for (const seg of item.segments) {
|
||||||
|
if (seg.origPoint && !seg.equals(seg.origPoint)) {
|
||||||
|
moved = true;
|
||||||
|
}
|
||||||
seg.origPoint = null;
|
seg.origPoint = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -193,8 +199,10 @@ class PointTool {
|
||||||
}
|
}
|
||||||
this.selectedItems = null;
|
this.selectedItems = null;
|
||||||
this.setSelectedItems();
|
this.setSelectedItems();
|
||||||
// @todo add back undo
|
if (moved) {
|
||||||
this.onUpdateSvg();
|
performSnapshot(this.undoSnapshot);
|
||||||
|
this.onUpdateSvg();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,18 +45,19 @@ class ReshapeTool extends paper.Tool {
|
||||||
* @param {function} clearSelectedItems Callback to clear the set of selected items in the Redux state
|
* @param {function} clearSelectedItems Callback to clear the set of selected items in the Redux state
|
||||||
* @param {!function} onUpdateSvg A callback to call when the image visibly changes
|
* @param {!function} onUpdateSvg A callback to call when the image visibly changes
|
||||||
*/
|
*/
|
||||||
constructor (setHoveredItem, clearHoveredItem, setSelectedItems, clearSelectedItems, onUpdateSvg) {
|
constructor (setHoveredItem, clearHoveredItem, setSelectedItems, clearSelectedItems, onUpdateSvg, undoSnapshot) {
|
||||||
super();
|
super();
|
||||||
this.setHoveredItem = setHoveredItem;
|
this.setHoveredItem = setHoveredItem;
|
||||||
this.clearHoveredItem = clearHoveredItem;
|
this.clearHoveredItem = clearHoveredItem;
|
||||||
this.onUpdateSvg = onUpdateSvg;
|
this.onUpdateSvg = onUpdateSvg;
|
||||||
|
this.undoSnapshot = undoSnapshot;
|
||||||
this.prevHoveredItemId = null;
|
this.prevHoveredItemId = null;
|
||||||
this.lastEvent = null;
|
this.lastEvent = null;
|
||||||
this.mode = ReshapeModes.SELECTION_BOX;
|
this.mode = ReshapeModes.SELECTION_BOX;
|
||||||
this._modeMap = {};
|
this._modeMap = {};
|
||||||
this._modeMap[ReshapeModes.FILL] = new MoveTool(setSelectedItems, clearSelectedItems, onUpdateSvg);
|
this._modeMap[ReshapeModes.FILL] = new MoveTool(setSelectedItems, clearSelectedItems, onUpdateSvg, undoSnapshot);
|
||||||
this._modeMap[ReshapeModes.POINT] = new PointTool(setSelectedItems, clearSelectedItems, onUpdateSvg);
|
this._modeMap[ReshapeModes.POINT] = new PointTool(setSelectedItems, clearSelectedItems, onUpdateSvg, undoSnapshot);
|
||||||
this._modeMap[ReshapeModes.HANDLE] = new HandleTool(setSelectedItems, clearSelectedItems, onUpdateSvg);
|
this._modeMap[ReshapeModes.HANDLE] = new HandleTool(setSelectedItems, clearSelectedItems, onUpdateSvg, undoSnapshot);
|
||||||
this._modeMap[ReshapeModes.SELECTION_BOX] =
|
this._modeMap[ReshapeModes.SELECTION_BOX] =
|
||||||
new SelectionBoxTool(Modes.RESHAPE, setSelectedItems, clearSelectedItems);
|
new SelectionBoxTool(Modes.RESHAPE, setSelectedItems, clearSelectedItems);
|
||||||
|
|
||||||
|
@ -221,7 +222,7 @@ class ReshapeTool extends paper.Tool {
|
||||||
handleKeyUp (event) {
|
handleKeyUp (event) {
|
||||||
// Backspace, delete
|
// Backspace, delete
|
||||||
if (event.key === 'delete' || event.key === 'backspace') {
|
if (event.key === 'delete' || event.key === 'backspace') {
|
||||||
deleteSelection(Modes.RESHAPE);
|
deleteSelection(Modes.RESHAPE, this.undoSnapshot);
|
||||||
this.onUpdateSvg();
|
this.onUpdateSvg();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import paper from 'paper';
|
import paper from 'paper';
|
||||||
|
import {performSnapshot} from '../undo';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tool to handle rotation when dragging the rotation handle in the bounding box tool.
|
* Tool to handle rotation when dragging the rotation handle in the bounding box tool.
|
||||||
|
@ -7,11 +8,12 @@ class RotateTool {
|
||||||
/**
|
/**
|
||||||
* @param {!function} onUpdateSvg A callback to call when the image visibly changes
|
* @param {!function} onUpdateSvg A callback to call when the image visibly changes
|
||||||
*/
|
*/
|
||||||
constructor (onUpdateSvg) {
|
constructor (onUpdateSvg, undoSnapshot) {
|
||||||
this.rotItems = [];
|
this.rotItems = [];
|
||||||
this.rotGroupPivot = null;
|
this.rotGroupPivot = null;
|
||||||
this.prevRot = [];
|
this.prevRot = [];
|
||||||
this.onUpdateSvg = onUpdateSvg;
|
this.onUpdateSvg = onUpdateSvg;
|
||||||
|
this.undoSnapshot = undoSnapshot;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -63,7 +65,7 @@ class RotateTool {
|
||||||
this.rotGroupPivot = null;
|
this.rotGroupPivot = null;
|
||||||
this.prevRot = [];
|
this.prevRot = [];
|
||||||
|
|
||||||
// @todo add back undo
|
performSnapshot(this.undoSnapshot);
|
||||||
this.onUpdateSvg();
|
this.onUpdateSvg();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import paper from 'paper';
|
import paper from 'paper';
|
||||||
|
import {performSnapshot} from '../undo';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tool to handle scaling items by pulling on the handles around the edges of the bounding
|
* Tool to handle scaling items by pulling on the handles around the edges of the bounding
|
||||||
|
@ -8,7 +9,7 @@ class ScaleTool {
|
||||||
/**
|
/**
|
||||||
* @param {!function} onUpdateSvg A callback to call when the image visibly changes
|
* @param {!function} onUpdateSvg A callback to call when the image visibly changes
|
||||||
*/
|
*/
|
||||||
constructor (onUpdateSvg) {
|
constructor (onUpdateSvg, undoSnapshot) {
|
||||||
this.pivot = null;
|
this.pivot = null;
|
||||||
this.origPivot = null;
|
this.origPivot = null;
|
||||||
this.corner = null;
|
this.corner = null;
|
||||||
|
@ -22,6 +23,7 @@ class ScaleTool {
|
||||||
this.boundsScaleHandles = [];
|
this.boundsScaleHandles = [];
|
||||||
this.boundsRotHandles = [];
|
this.boundsRotHandles = [];
|
||||||
this.onUpdateSvg = onUpdateSvg;
|
this.onUpdateSvg = onUpdateSvg;
|
||||||
|
this.undoSnapshot = undoSnapshot;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -157,7 +159,7 @@ class ScaleTool {
|
||||||
}
|
}
|
||||||
this.itemGroup.remove();
|
this.itemGroup.remove();
|
||||||
|
|
||||||
// @todo add back undo
|
performSnapshot(this.undoSnapshot);
|
||||||
this.onUpdateSvg();
|
this.onUpdateSvg();
|
||||||
}
|
}
|
||||||
_getRectCornerNameByIndex (index) {
|
_getRectCornerNameByIndex (index) {
|
||||||
|
|
|
@ -25,12 +25,12 @@ class SelectTool extends paper.Tool {
|
||||||
* @param {function} clearSelectedItems Callback to clear the set of selected items in the Redux state
|
* @param {function} clearSelectedItems Callback to clear the set of selected items in the Redux state
|
||||||
* @param {!function} onUpdateSvg A callback to call when the image visibly changes
|
* @param {!function} onUpdateSvg A callback to call when the image visibly changes
|
||||||
*/
|
*/
|
||||||
constructor (setHoveredItem, clearHoveredItem, setSelectedItems, clearSelectedItems, onUpdateSvg) {
|
constructor (setHoveredItem, clearHoveredItem, setSelectedItems, clearSelectedItems, onUpdateSvg, undoSnapshot) {
|
||||||
super();
|
super();
|
||||||
this.setHoveredItem = setHoveredItem;
|
this.setHoveredItem = setHoveredItem;
|
||||||
this.clearHoveredItem = clearHoveredItem;
|
this.clearHoveredItem = clearHoveredItem;
|
||||||
this.onUpdateSvg = onUpdateSvg;
|
this.onUpdateSvg = onUpdateSvg;
|
||||||
this.boundingBoxTool = new BoundingBoxTool(setSelectedItems, clearSelectedItems, onUpdateSvg);
|
this.boundingBoxTool = new BoundingBoxTool(setSelectedItems, clearSelectedItems, onUpdateSvg, undoSnapshot);
|
||||||
this.selectionBoxTool = new SelectionBoxTool(Modes.SELECT, setSelectedItems, clearSelectedItems);
|
this.selectionBoxTool = new SelectionBoxTool(Modes.SELECT, setSelectedItems, clearSelectedItems);
|
||||||
this.selectionBoxMode = false;
|
this.selectionBoxMode = false;
|
||||||
this.prevHoveredItemId = null;
|
this.prevHoveredItemId = null;
|
||||||
|
@ -126,7 +126,7 @@ class SelectTool extends paper.Tool {
|
||||||
handleKeyUp (event) {
|
handleKeyUp (event) {
|
||||||
// Backspace, delete
|
// Backspace, delete
|
||||||
if (event.key === 'delete' || event.key === 'backspace') {
|
if (event.key === 'delete' || event.key === 'backspace') {
|
||||||
deleteSelection(Modes.SELECT);
|
deleteSelection(Modes.SELECT, this.undoSnapshot);
|
||||||
this.clearHoveredItem();
|
this.clearHoveredItem();
|
||||||
this.boundingBoxTool.removeBoundsPath();
|
this.boundingBoxTool.removeBoundsPath();
|
||||||
this.onUpdateSvg();
|
this.onUpdateSvg();
|
||||||
|
|
|
@ -4,6 +4,7 @@ import Modes from '../modes/modes';
|
||||||
import {getItemsGroup, isGroup} from './group';
|
import {getItemsGroup, isGroup} from './group';
|
||||||
import {getRootItem, isCompoundPathItem, isBoundsItem, isPathItem, isPGTextItem} from './item';
|
import {getRootItem, isCompoundPathItem, isBoundsItem, isPathItem, isPGTextItem} from './item';
|
||||||
import {getItemsCompoundPath, isCompoundPath, isCompoundPathChild} from './compound-path';
|
import {getItemsCompoundPath, isCompoundPath, isCompoundPathChild} from './compound-path';
|
||||||
|
import {performSnapshot} from './undo';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {boolean} includeGuides True if guide layer items like the bounding box should
|
* @param {boolean} includeGuides True if guide layer items like the bounding box should
|
||||||
|
@ -165,20 +166,18 @@ const getSelectedLeafItems = function () {
|
||||||
return items;
|
return items;
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteItemSelection = function (items) {
|
const deleteItemSelection = function (items, undoSnapshot) {
|
||||||
for (let i = 0; i < items.length; i++) {
|
for (let i = 0; i < items.length; i++) {
|
||||||
items[i].remove();
|
items[i].remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
// @todo: Update toolbar state on change
|
// @todo: Update toolbar state on change
|
||||||
paper.project.view.update();
|
paper.project.view.update();
|
||||||
// @todo add back undo
|
performSnapshot(undoSnapshot);
|
||||||
// pg.undo.snapshot('deleteItemSelection');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeSelectedSegments = function (items) {
|
const removeSelectedSegments = function (items, undoSnapshot) {
|
||||||
// @todo add back undo
|
performSnapshot(undoSnapshot);
|
||||||
// pg.undo.snapshot('removeSelectedSegments');
|
|
||||||
|
|
||||||
const segmentsToRemove = [];
|
const segmentsToRemove = [];
|
||||||
|
|
||||||
|
@ -201,16 +200,16 @@ const removeSelectedSegments = function (items) {
|
||||||
return removedSegments;
|
return removedSegments;
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteSelection = function (mode) {
|
const deleteSelection = function (mode, undoSnapshot) {
|
||||||
if (mode === Modes.RESHAPE) {
|
if (mode === Modes.RESHAPE) {
|
||||||
const selectedItems = getSelectedLeafItems();
|
const selectedItems = getSelectedLeafItems();
|
||||||
// If there are points selected remove them. If not delete the item selected.
|
// If there are points selected remove them. If not delete the item selected.
|
||||||
if (!removeSelectedSegments(selectedItems)) {
|
if (!removeSelectedSegments(selectedItems, undoSnapshot)) {
|
||||||
deleteItemSelection(selectedItems);
|
deleteItemSelection(selectedItems, undoSnapshot);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const selectedItems = getSelectedRootItems();
|
const selectedItems = getSelectedRootItems();
|
||||||
deleteItemSelection(selectedItems);
|
deleteItemSelection(selectedItems, undoSnapshot);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -281,11 +280,11 @@ const splitPathAtSelectedSegments = function () {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteSegments = function (item) {
|
const deleteSegments = function (item, undoSnapshot) {
|
||||||
if (item.children) {
|
if (item.children) {
|
||||||
for (let i = 0; i < item.children.length; i++) {
|
for (let i = 0; i < item.children.length; i++) {
|
||||||
const child = item.children[i];
|
const child = item.children[i];
|
||||||
deleteSegments(child);
|
deleteSegments(child, undoSnapshot);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const segments = item.segments;
|
const segments = item.segments;
|
||||||
|
@ -299,7 +298,7 @@ const deleteSegments = function (item) {
|
||||||
!segment.previous.selected)) {
|
!segment.previous.selected)) {
|
||||||
|
|
||||||
splitPathRetainSelection(item, j);
|
splitPathRetainSelection(item, j);
|
||||||
deleteSelection();
|
deleteSelection(Modes.RESHAPE, undoSnapshot);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
} else if (!item.closed) {
|
} else if (!item.closed) {
|
||||||
|
@ -316,26 +315,24 @@ const deleteSegments = function (item) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteSegmentSelection = function (items) {
|
const deleteSegmentSelection = function (items, undoSnapshot) {
|
||||||
for (let i = 0; i < items.length; i++) {
|
for (let i = 0; i < items.length; i++) {
|
||||||
deleteSegments(items[i]);
|
deleteSegments(items[i], undoSnapshot);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @todo: Update toolbar state on change
|
// @todo: Update toolbar state on change
|
||||||
paper.project.view.update();
|
paper.project.view.update();
|
||||||
// @todo add back undo
|
performSnapshot(undoSnapshot);
|
||||||
// pg.undo.snapshot('deleteSegmentSelection');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const cloneSelection = function (recursive) {
|
const cloneSelection = function (recursive, undoSnapshot) {
|
||||||
const selectedItems = recursive ? getSelectedLeafItems() : getSelectedRootItems();
|
const selectedItems = recursive ? getSelectedLeafItems() : getSelectedRootItems();
|
||||||
for (let i = 0; i < selectedItems.length; i++) {
|
for (let i = 0; i < selectedItems.length; i++) {
|
||||||
const item = selectedItems[i];
|
const item = selectedItems[i];
|
||||||
item.clone();
|
item.clone();
|
||||||
item.selected = false;
|
item.selected = false;
|
||||||
}
|
}
|
||||||
// @todo add back undo
|
performSnapshot(undoSnapshot);
|
||||||
// pg.undo.snapshot('cloneSelection');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Only returns paths, no compound paths, groups or any other stuff
|
// Only returns paths, no compound paths, groups or any other stuff
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import {getSelectedLeafItems} from './selection';
|
import {getSelectedLeafItems} from './selection';
|
||||||
import {isPGTextItem, isPointTextItem} from './item';
|
import {isPGTextItem, isPointTextItem} from './item';
|
||||||
import {isGroup} from './group';
|
import {isGroup} from './group';
|
||||||
|
import {performSnapshot} from './undo';
|
||||||
|
|
||||||
const MIXED = 'scratch-paint/style-path/mixed';
|
const MIXED = 'scratch-paint/style-path/mixed';
|
||||||
|
|
||||||
|
@ -8,7 +9,7 @@ const MIXED = 'scratch-paint/style-path/mixed';
|
||||||
* Called when setting fill color
|
* Called when setting fill color
|
||||||
* @param {string} colorString New color, css format
|
* @param {string} colorString New color, css format
|
||||||
*/
|
*/
|
||||||
const applyFillColorToSelection = function (colorString) {
|
const applyFillColorToSelection = function (colorString, undoSnapshot) {
|
||||||
const items = getSelectedLeafItems();
|
const items = getSelectedLeafItems();
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
if (isPGTextItem(item)) {
|
if (isPGTextItem(item)) {
|
||||||
|
@ -30,14 +31,14 @@ const applyFillColorToSelection = function (colorString) {
|
||||||
item.fillColor = colorString;
|
item.fillColor = colorString;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// @todo add back undo
|
performSnapshot(undoSnapshot);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when setting stroke color
|
* Called when setting stroke color
|
||||||
* @param {string} colorString New color, css format
|
* @param {string} colorString New color, css format
|
||||||
*/
|
*/
|
||||||
const applyStrokeColorToSelection = function (colorString) {
|
const applyStrokeColorToSelection = function (colorString, undoSnapshot) {
|
||||||
const items = getSelectedLeafItems();
|
const items = getSelectedLeafItems();
|
||||||
|
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
|
@ -61,14 +62,14 @@ const applyStrokeColorToSelection = function (colorString) {
|
||||||
item.strokeColor = colorString;
|
item.strokeColor = colorString;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// @todo add back undo
|
performSnapshot(undoSnapshot);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when setting stroke width
|
* Called when setting stroke width
|
||||||
* @param {number} value New stroke width
|
* @param {number} value New stroke width
|
||||||
*/
|
*/
|
||||||
const applyStrokeWidthToSelection = function (value) {
|
const applyStrokeWidthToSelection = function (value, undoSnapshot) {
|
||||||
const items = getSelectedLeafItems();
|
const items = getSelectedLeafItems();
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
if (isGroup(item)) {
|
if (isGroup(item)) {
|
||||||
|
@ -77,7 +78,7 @@ const applyStrokeWidthToSelection = function (value) {
|
||||||
item.strokeWidth = value;
|
item.strokeWidth = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// @todo add back undo
|
performSnapshot(undoSnapshot);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -168,7 +169,12 @@ const stylePath = function (path, options) {
|
||||||
if (options.isEraser) {
|
if (options.isEraser) {
|
||||||
path.fillColor = 'white';
|
path.fillColor = 'white';
|
||||||
} else {
|
} else {
|
||||||
path.fillColor = options.fillColor;
|
if (options.fillColor) {
|
||||||
|
path.fillColor = options.fillColor;
|
||||||
|
} else {
|
||||||
|
// Make sure something visible is drawn
|
||||||
|
path.fillColor = 'black';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -178,7 +184,12 @@ const styleCursorPreview = function (path, options) {
|
||||||
path.strokeColor = 'cornflowerblue';
|
path.strokeColor = 'cornflowerblue';
|
||||||
path.strokeWidth = 1;
|
path.strokeWidth = 1;
|
||||||
} else {
|
} else {
|
||||||
path.fillColor = options.fillColor;
|
if (options.fillColor) {
|
||||||
|
path.fillColor = options.fillColor;
|
||||||
|
} else {
|
||||||
|
// Make sure something visible is drawn
|
||||||
|
path.fillColor = 'black';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import eraserModeReducer from './eraser-mode';
|
||||||
import colorReducer from './color';
|
import colorReducer from './color';
|
||||||
import hoverReducer from './hover';
|
import hoverReducer from './hover';
|
||||||
import selectedItemReducer from './selected-items';
|
import selectedItemReducer from './selected-items';
|
||||||
|
import undoReducer from './undo';
|
||||||
|
|
||||||
export default combineReducers({
|
export default combineReducers({
|
||||||
mode: modeReducer,
|
mode: modeReducer,
|
||||||
|
@ -12,5 +13,6 @@ export default combineReducers({
|
||||||
eraserMode: eraserModeReducer,
|
eraserMode: eraserModeReducer,
|
||||||
color: colorReducer,
|
color: colorReducer,
|
||||||
hoveredItemId: hoverReducer,
|
hoveredItemId: hoverReducer,
|
||||||
selectedItems: selectedItemReducer
|
selectedItems: selectedItemReducer,
|
||||||
|
undo: undoReducer
|
||||||
});
|
});
|
||||||
|
|
|
@ -13,7 +13,7 @@ const reducer = function (state, action) {
|
||||||
if (typeof state === 'undefined') state = initialState;
|
if (typeof state === 'undefined') state = initialState;
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case UNDO:
|
case UNDO:
|
||||||
if (state.pointer === -1) {
|
if (state.pointer <= 0) {
|
||||||
log.warn(`Can't undo, undo stack is empty`);
|
log.warn(`Can't undo, undo stack is empty`);
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ const reducer = function (state, action) {
|
||||||
pointer: state.pointer - 1
|
pointer: state.pointer - 1
|
||||||
};
|
};
|
||||||
case REDO:
|
case REDO:
|
||||||
if (state.pointer === state.stack.length - 1) {
|
if (state.pointer <= -1 || state.pointer === state.stack.length - 1) {
|
||||||
log.warn(`Can't redo, redo stack is empty`);
|
log.warn(`Can't redo, redo stack is empty`);
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,12 +52,20 @@ test('clearUndoState', () => {
|
||||||
|
|
||||||
test('cantUndo', () => {
|
test('cantUndo', () => {
|
||||||
let defaultState;
|
let defaultState;
|
||||||
|
const state1 = {state: 1};
|
||||||
|
|
||||||
// Undo when there's no undo stack
|
// Undo when there's no undo stack
|
||||||
const reduxState = undoReducer(defaultState /* state */, undo() /* action */);
|
let reduxState = undoReducer(defaultState /* state */, undo() /* action */);
|
||||||
|
|
||||||
expect(reduxState.pointer).toEqual(-1);
|
expect(reduxState.pointer).toEqual(-1);
|
||||||
expect(reduxState.stack).toHaveLength(0);
|
expect(reduxState.stack).toHaveLength(0);
|
||||||
|
|
||||||
|
// Undo when there's only one state
|
||||||
|
reduxState = undoReducer(reduxState /* state */, undoSnapshot([state1]) /* action */);
|
||||||
|
reduxState = undoReducer(reduxState /* state */, undo() /* action */);
|
||||||
|
|
||||||
|
expect(reduxState.pointer).toEqual(0);
|
||||||
|
expect(reduxState.stack).toHaveLength(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('cantRedo', () => {
|
test('cantRedo', () => {
|
||||||
|
@ -111,23 +119,23 @@ test('undoSnapshotCantRedo', () => {
|
||||||
let defaultState;
|
let defaultState;
|
||||||
const state1 = {state: 1};
|
const state1 = {state: 1};
|
||||||
const state2 = {state: 2};
|
const state2 = {state: 2};
|
||||||
|
const state3 = {state: 3};
|
||||||
|
|
||||||
// Push 2 states then undo twice
|
// Push 2 states then undo
|
||||||
let reduxState = undoReducer(defaultState /* state */, undoSnapshot([state1]) /* action */);
|
let reduxState = undoReducer(defaultState /* state */, undoSnapshot([state1]) /* action */);
|
||||||
reduxState = undoReducer(reduxState /* state */, undoSnapshot([state2]) /* action */);
|
reduxState = undoReducer(reduxState /* state */, undoSnapshot([state2]) /* action */);
|
||||||
reduxState = undoReducer(reduxState /* state */, undo() /* action */);
|
reduxState = undoReducer(reduxState /* state */, undo() /* action */);
|
||||||
reduxState = undoReducer(reduxState /* state */, undo() /* action */);
|
|
||||||
|
|
||||||
expect(reduxState.pointer).toEqual(-1);
|
expect(reduxState.pointer).toEqual(0);
|
||||||
expect(reduxState.stack).toHaveLength(2);
|
expect(reduxState.stack).toHaveLength(2);
|
||||||
|
|
||||||
// Snapshot
|
// Snapshot
|
||||||
reduxState = undoReducer(reduxState /* state */, undoSnapshot([state2]) /* action */);
|
reduxState = undoReducer(reduxState /* state */, undoSnapshot([state3]) /* action */);
|
||||||
// Redo should do nothing
|
// Redo should do nothing
|
||||||
const newReduxState = undoReducer(reduxState /* state */, redo() /* action */);
|
const newReduxState = undoReducer(reduxState /* state */, redo() /* action */);
|
||||||
|
|
||||||
expect(newReduxState.pointer).toEqual(reduxState.pointer);
|
expect(newReduxState.pointer).toEqual(reduxState.pointer);
|
||||||
expect(newReduxState.stack).toHaveLength(reduxState.stack.length);
|
expect(newReduxState.stack).toHaveLength(reduxState.stack.length);
|
||||||
expect(newReduxState.stack[0]).toEqual(reduxState.stack[0]);
|
expect(newReduxState.stack[0]).toEqual(reduxState.stack[0]);
|
||||||
expect(newReduxState.stack[0]).toEqual(state2);
|
expect(newReduxState.stack[1]).toEqual(state3);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue