mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-23 12:45:48 +00:00
change selectionKey interface to not be a breaking change but still accept an array (#4363)
This commit is contained in:
parent
d88af28af7
commit
8f4fb458bf
2 changed files with 24 additions and 25 deletions
|
|
@ -127,15 +127,16 @@
|
|||
selection: true,
|
||||
|
||||
/**
|
||||
* Indicates which keys enable multiple click selection
|
||||
* Indicates which key or keys enable multiple click selection
|
||||
* Pass value as a string or array of strings
|
||||
* values: 'altKey', 'shiftKey', 'ctrlKey'.
|
||||
* If `null` or empty or containing any other string that is not a modifier key
|
||||
* feature is disabled.
|
||||
* @since 1.6.2
|
||||
* @type Array
|
||||
* @type String|Array
|
||||
* @default
|
||||
*/
|
||||
selectionKeys: ['shiftKey'],
|
||||
selectionKey: 'shiftKey',
|
||||
|
||||
/**
|
||||
* Indicates which key enable alternative selection
|
||||
|
|
@ -507,6 +508,24 @@
|
|||
return isTransparent;
|
||||
},
|
||||
|
||||
/**
|
||||
* takes an event and determins if selection key has been pressed
|
||||
* @private
|
||||
* @param {Event} e Event object
|
||||
*/
|
||||
_isSelectionKeyPressed: function(e) {
|
||||
var selectionKeyPressed = false;
|
||||
|
||||
if (Object.prototype.toString.call(this.selectionKey) === '[object Array]') {
|
||||
selectionKeyPressed = !!this.selectionKey.find(function(key) { return e[key] === true; });
|
||||
}
|
||||
else {
|
||||
selectionKeyPressed = e[this.selectionKey];
|
||||
}
|
||||
|
||||
return selectionKeyPressed;
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {Event} e Event object
|
||||
|
|
@ -516,16 +535,6 @@
|
|||
var activeObjects = this.getActiveObjects(),
|
||||
activeObject = this._activeObject;
|
||||
|
||||
var selectionKeyPressed = false;
|
||||
if (Array.isArray(this.selectionKeys)){
|
||||
selectionKeyPressed = this.selectionKeys.some(function (selectionKey) {
|
||||
return e[selectionKey];
|
||||
});
|
||||
}
|
||||
else if (e[this.selectionKeys.toString()]){
|
||||
selectionKeyPressed = true;
|
||||
}
|
||||
|
||||
return (
|
||||
!target
|
||||
||
|
||||
|
|
@ -534,7 +543,7 @@
|
|||
activeObjects.length > 1 &&
|
||||
activeObjects.indexOf(target) === -1 &&
|
||||
activeObject !== target &&
|
||||
!selectionKeyPressed)
|
||||
!this._isSelectionKeyPressed(e))
|
||||
||
|
||||
(target && !target.evented)
|
||||
||
|
||||
|
|
|
|||
|
|
@ -14,17 +14,7 @@
|
|||
_shouldGroup: function(e, target) {
|
||||
var activeObject = this._activeObject;
|
||||
|
||||
var selectionKeyPressed = false;
|
||||
if (Array.isArray(this.selectionKeys)){
|
||||
selectionKeyPressed = this.selectionKeys.some(function (selectionKey) {
|
||||
return e[selectionKey];
|
||||
});
|
||||
}
|
||||
else if (e[this.selectionKeys.toString()]){
|
||||
selectionKeyPressed = true;
|
||||
}
|
||||
|
||||
return activeObject && selectionKeyPressed && target && target.selectable && this.selection &&
|
||||
return activeObject && this._isSelectionKeyPressed(e) && target && target.selectable && this.selection &&
|
||||
(activeObject !== target || activeObject.type === 'activeSelection');
|
||||
},
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue