Skip to content

Commit

Permalink
feat: undo chage from group selection = #1
Browse files Browse the repository at this point in the history
  • Loading branch information
jinwoo-kim-nhn committed Dec 1, 2020
1 parent 73c889c commit ded1ed4
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ import './js/command/resizeCanvasDimension';
import './js/command/rotate';
import './js/command/setObjectProperties';
import './js/command/setObjectPosition';
import './js/command/moveResizeFromSelection';

module.exports = ImageEditor;
41 changes: 41 additions & 0 deletions src/js/command/moveResizeFromSelection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* @author NHN Ent. FE Development Team <dl_javascript@nhn.com>
* @fileoverview Set object properties
*/
import commandFactory from '../factory/command';
// import {Promise} from '../util';
// import {commandNames, rejectMessages} from '../consts';

const command = {
name: 'moveResizeFromSelection',

execute(graphics, id, props) {
/*
const targetObj = graphics.getObject(id);
this.undoData.props = {};
snippet.forEachOwnProperties(props, (value, key) => {
this.undoData.props[key] = targetObj[key];
});
graphics.setObjectProperties(id, props);
return Promise.resolve();
*/
},
undo(graphics, id) {
/*
const {props} = this.undoData;
console.log('Undo', props);
graphics.setObjectProperties(id, props);
return Promise.resolve();
*/
}
};

commandFactory.register(command);

export default command;
3 changes: 1 addition & 2 deletions src/js/graphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -989,9 +989,8 @@ class Graphics {
*/
_onMouseDown(fEvent) {
const originPointer = this._canvas.getPointer(fEvent.e);
const props = fEvent.target ? this.createObjectProperties(fEvent.target) : null;

this.fire(events.MOUSE_DOWN, fEvent.e, originPointer, props);
this.fire(events.MOUSE_DOWN, fEvent.e, originPointer, fEvent.target);
}

/**
Expand Down
15 changes: 8 additions & 7 deletions src/js/imageEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ class ImageEditor {
* @param {Number} originPointer.y y position
* @private
*/
_onMouseDown(event, originPointer, props) {
_onMouseDown(event, originPointer, obj) {
/**
* The mouse down event with position x, y on canvas
* @event ImageEditor#mousedown
Expand All @@ -413,13 +413,14 @@ class ImageEditor {
* }
* });
*/
if (props) {

if (obj) {
this._invoker.cacheUndoDataForChangeDimension = extend({}, {
left: props.left,
top: props.top,
width: props.width,
height: props.height,
angle: props.angle
left: obj.left,
top: obj.top,
width: obj.width,
height: obj.height,
angle: obj.angle
});
}

Expand Down

0 comments on commit ded1ed4

Please sign in to comment.