diff --git a/src/mixins/canvas_events.mixin.js b/src/mixins/canvas_events.mixin.js index 6d4cbac1704..b60fd38ae83 100644 --- a/src/mixins/canvas_events.mixin.js +++ b/src/mixins/canvas_events.mixin.js @@ -497,10 +497,13 @@ this._beforeTransform(e, target); this._setupCurrentTransform(e, target); } - - if (target !== this.getActiveGroup() && target !== this.getActiveObject()) { + var activeObject = this.getActiveObject(); + if (target !== this.getActiveGroup() && target !== activeObject) { this.deactivateAll(); - target.selectable && this.setActiveObject(target, e); + if (target.selectable) { + activeObject.fire('deselected', { e: e }); + this.setActiveObject(target, e); + } } } this._handleEvent(e, 'down', target ? target : null); diff --git a/test/unit/canvas.js b/test/unit/canvas.js index 328a4a4917e..19cd4504ad4 100644 --- a/test/unit/canvas.js +++ b/test/unit/canvas.js @@ -296,6 +296,17 @@ equal(isFired, true, 'removing active object should fire "selection:cleared"'); }); + test('setActiveObject fires deselected', function() { + var isFired = false; + var rect1 = new fabric.Rect(); + var rect2 = new fabric.Rect(); + rect1.on('deselected', function() { isFired = true; }); + + canvas.setActiveObject(rect1); + canvas.setActiveObject(rect2); + equal(isFired, true, 'switching active group fires deselected'); + }); + test('getContext', function() { ok(typeof canvas.getContext == 'function'); });