Skip to content

Commit

Permalink
Firedeselectedalsowithmouse (#3716)
Browse files Browse the repository at this point in the history
* added code

* added test
  • Loading branch information
asturur authored Feb 19, 2017
1 parent b9d4888 commit 54f76a1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/mixins/canvas_events.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions test/unit/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand Down

0 comments on commit 54f76a1

Please sign in to comment.