From c5ccd2386f4c371b66ade5d1b7ffbbee5a9212bc Mon Sep 17 00:00:00 2001 From: Asturur Date: Sat, 18 Feb 2017 22:22:03 -0500 Subject: [PATCH 1/2] added code --- src/mixins/canvas_events.mixin.js | 9 ++++++--- 1 file changed, 6 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); From 733e5de118feb1328ddd16218a6edf90c9c9d558 Mon Sep 17 00:00:00 2001 From: Asturur Date: Sat, 18 Feb 2017 22:25:13 -0500 Subject: [PATCH 2/2] added test --- test/unit/canvas.js | 11 +++++++++++ 1 file changed, 11 insertions(+) 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'); });