From c0c222f6724767a80f3d04ecc0ba4cdacc5178ed Mon Sep 17 00:00:00 2001 From: kangax Date: Fri, 25 Oct 2013 10:38:32 +0200 Subject: [PATCH] Refactor _handleGroupLogic --- src/canvas.class.js | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/src/canvas.class.js b/src/canvas.class.js index 3d06d403..5fc99bee 100644 --- a/src/canvas.class.js +++ b/src/canvas.class.js @@ -504,29 +504,33 @@ activeGroup.set('active', true); } else { - // group does not exist - if (this._activeObject) { - // only if there's an active object - if (target !== this._activeObject) { - // and that object is not the actual target - var objects = this.getObjects(); - var isActiveLower = objects.indexOf(this._activeObject) < objects.indexOf(target); - var group = new fabric.Group( - isActiveLower ? [ target, this._activeObject ] : [ this._activeObject, target ]); + this._createActiveGroup(target, e); + } - this.setActiveGroup(group); - this._activeObject = null; - activeGroup = this.getActiveGroup(); - this.fire('selection:created', { target: activeGroup, e: e }); - } + if (this._activeGroup) { + this._activeGroup.saveCoords(); + } + }, + + _createActiveGroup: function(target, e) { + // group does not exist + if (this._activeObject) { + // only if there's an active object + if (target !== this._activeObject) { + // and that object is not the actual target + var objects = this.getObjects(); + var isActiveLower = objects.indexOf(this._activeObject) < objects.indexOf(target); + var group = new fabric.Group( + isActiveLower ? [ target, this._activeObject ] : [ this._activeObject, target ]); + + this.setActiveGroup(group); + this._activeObject = null; + var activeGroup = this.getActiveGroup(); + this.fire('selection:created', { target: activeGroup, e: e }); } - // activate target object in any case - target.set('active', true); - } - - if (activeGroup) { - activeGroup.saveCoords(); } + // activate target object in any case + target.set('active', true); }, /**