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

Added activeOn 'up/down' property #6807

Merged
merged 11 commits into from
Jan 30, 2021
30 changes: 30 additions & 0 deletions src/mixins/canvas_events.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,22 @@
}
}
if (target) {
if (target.selectable && target !== this._activeObject) {
if (fabric.util.isTouchEvent(e)) {
var activeOnDown = (target.setActiveOn === 'mouseuptouchdown' ||
target.setActiveOn === 'mousetouchdown');
}
else {
var activeOnDown = (target.setActiveOn === 'mousetouchdown' ||
target.setActiveOn === 'mousedowntouchup');
}
if (!activeOnDown) {
this.setActiveObject(target, e);
this._handleEvent(e, 'up', LEFT_CLICK, isClick);
this.requestRenderAll();
return;
}
}
var corner = target._findTargetCorner(
this.getPointer(e, true),
fabric.util.isTouchEvent(e)
Expand Down Expand Up @@ -715,6 +731,20 @@

if (target) {
var alreadySelected = target === this._activeObject;
if (!alreadySelected) {
if (fabric.util.isTouchEvent(e)) {
var activeOnDown = (target.setActiveOn === 'mouseuptouchdown' ||
target.setActiveOn === 'mousetouchdown');
}
else {
var activeOnDown = (target.setActiveOn === 'mousetouchdown' ||
target.setActiveOn === 'mousedowntouchup');
}
if (!activeOnDown) {
this._handleEvent(e, 'down');
return;
melchiar marked this conversation as resolved.
Show resolved Hide resolved
}
}
if (target.selectable) {
this.setActiveObject(target, e);
}
Expand Down
11 changes: 11 additions & 0 deletions src/shapes/object.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,17 @@
*/
paintFirst: 'fill',

/**
* When 'mousetouchdown', object is set to active on mousedown/touchdown
* When 'mousedowntouchup', object is set to active on mousedown/touchup
* When 'mouseuptouchdown', object is set to active on mouseup/touchdown
* When 'mousetouchup', object is set to active on mouseup/touchup
* since 4.4.0
* @type String
* @default 'mousetouchdown'
*/
setActiveOn: 'mousetouchdown',

/**
* List of properties to consider when checking if state
* of an object is changed (fabric.Object#hasStateChanged)
Expand Down