Allow multiple keys to enable multiple click selection (#4184)

* Allow multiple keys to enable multiple click selection

* backwards compatibility: allow string or array

* do isArray properly

* forgot a this.

* formatting...

* more formatting...
This commit is contained in:
Brian Chitester 2017-09-29 13:40:36 -04:00 committed by Andrea Bogazzi
parent 052631bdcb
commit d88af28af7
2 changed files with 29 additions and 7 deletions

View file

@ -127,15 +127,15 @@
selection: true,
/**
* Indicates which key enable multiple click selection
* Indicates which keys enable multiple click selection
* values: 'altKey', 'shiftKey', 'ctrlKey'.
* If `null` or 'none' or any other string that is not a modifier key
* feature is disabled feature disabled.
* If `null` or empty or containing any other string that is not a modifier key
* feature is disabled.
* @since 1.6.2
* @type String
* @type Array
* @default
*/
selectionKey: 'shiftKey',
selectionKeys: ['shiftKey'],
/**
* Indicates which key enable alternative selection
@ -515,6 +515,17 @@
_shouldClearSelection: function (e, target) {
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
||
@ -523,7 +534,7 @@
activeObjects.length > 1 &&
activeObjects.indexOf(target) === -1 &&
activeObject !== target &&
!e[this.selectionKey])
!selectionKeyPressed)
||
(target && !target.evented)
||

View file

@ -13,7 +13,18 @@
*/
_shouldGroup: function(e, target) {
var activeObject = this._activeObject;
return activeObject && e[this.selectionKey] && target && target.selectable && this.selection &&
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 &&
(activeObject !== target || activeObject.type === 'activeSelection');
},