From 54f76a1066776adce365637d41f0b56338872cb1 Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Sat, 18 Feb 2017 23:03:23 -0500 Subject: [PATCH] Firedeselectedalsowithmouse (#3716) * added code * added test --- src/mixins/canvas_events.mixin.js | 9 ++++++--- test/unit/canvas.js | 11 +++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) 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'); });