Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(): stop transforming on discardActiveObject #7954

Merged
merged 5 commits into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/canvas.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,7 @@
/**
* This is a private method for now.
* This is supposed to be equivalent to discardActiveObject but without firing
* any events. There is commitment to have this stay this way.
* any selection events ( can still fire object transformation events ). There is commitment to have this stay this way.
* This is the functional part of discardActiveObject.
* @param {Event} [e] Event (passed along when firing "object:deselected")
* @param {Object} object to set as active
Expand All @@ -1243,6 +1243,9 @@
if (obj.onDeselect({ e: e, object: object })) {
return false;
}
if (this._currentTransform && this._currentTransform.target === obj) {
ShaMan123 marked this conversation as resolved.
Show resolved Hide resolved
this.endCurrentTransform(e);
}
this._activeObject = null;
}
return true;
Expand Down
16 changes: 16 additions & 0 deletions src/mixins/canvas_events.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,22 @@
}
},

/**
* End the current transfrom.
* You don't usually need to call this method unless you are interupting a user initiated transform
* because of some other event ( a press of key combination, or something that block the user UX )
* @param {Event} [e] send the mouse event that generate the finalize down, so it can be used in the event
*/
endCurrentTransform: function(e) {
var transform = this._currentTransform;
this._finalizeCurrentTransform(e);
if (transform && transform.target) {
// this could probably go inside _finalizeCurrentTransform
transform.target.isMoving = false;
};
this._currentTransform = null;
},

/**
* @private
* @param {Event} e send the mouse event that generate the finalize down, so it can be used in the event
Expand Down
16 changes: 14 additions & 2 deletions test/unit/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -1977,7 +1977,20 @@
canvas.setActiveObject(canvas.item(0));

canvas._discardActiveObject();
assert.ok(!canvas.item(0).active);
assert.equal(canvas.getActiveObject(), null);
});

QUnit.test('_discardActiveObject - cleanup transform', function (assert) {
var e = { clientX: 5, clientY: 5, which: 1, target: canvas.upperCanvasEl };
var target = makeRect();
canvas.add(target);
canvas.setActiveObject(target);
canvas._setupCurrentTransform(e, target, true);
assert.ok(canvas._currentTransform, 'transform should be set');
target.isMoving = true;
canvas._discardActiveObject();
assert.ok(!canvas._currentTransform, 'transform should be cleared');
assert.ok(!target.isMoving, 'moving flag should have been negated');
assert.equal(canvas.getActiveObject(), null);
});

Expand All @@ -2003,7 +2016,6 @@
});

canvas.discardActiveObject();
assert.ok(!canvas.item(0).active);
assert.equal(canvas.getActiveObject(), null);
assert.equal(canvas.getActiveObject(), null);

Expand Down