From 767cf6a68e42e5fe5de536d23025f6f147ed9e26 Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Sat, 22 Sep 2018 21:37:08 +0200 Subject: [PATCH 1/4] better-than-nothing --- src/mixins/canvas_events.mixin.js | 2 +- src/mixins/itext_click_behavior.mixin.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/mixins/canvas_events.mixin.js b/src/mixins/canvas_events.mixin.js index a8f1b249753..f092534a339 100644 --- a/src/mixins/canvas_events.mixin.js +++ b/src/mixins/canvas_events.mixin.js @@ -620,7 +620,7 @@ } this._handleEvent(e, 'down'); // we must renderAll so that we update the visuals - shouldRender && this.requestRenderAll(); + (shouldRender || shouldGroup) && this.requestRenderAll(); }, /** diff --git a/src/mixins/itext_click_behavior.mixin.js b/src/mixins/itext_click_behavior.mixin.js index 14ceb0c4301..cda0e513d9d 100644 --- a/src/mixins/itext_click_behavior.mixin.js +++ b/src/mixins/itext_click_behavior.mixin.js @@ -139,6 +139,15 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot return; } + if (this.canvas) { + if (this.canvas._activeObject !== this) { + // avoid running this logic when there is an active object + // this because is possible with shift click and fast clicks, + // to rapidly deselect and reselect this object and trigger an enterEdit + return; + } + } + if (this.__lastSelected && !this.__corner) { this.selected = false; this.__lastSelected = false; From 5d37153dff3b7889757287d8f3fbf17a46cb81cd Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Sat, 22 Sep 2018 21:50:41 +0200 Subject: [PATCH 2/4] check that the active object exist --- src/mixins/itext_click_behavior.mixin.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mixins/itext_click_behavior.mixin.js b/src/mixins/itext_click_behavior.mixin.js index cda0e513d9d..2aea508f156 100644 --- a/src/mixins/itext_click_behavior.mixin.js +++ b/src/mixins/itext_click_behavior.mixin.js @@ -140,7 +140,8 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot } if (this.canvas) { - if (this.canvas._activeObject !== this) { + var currentActive = this.canvas._activeObject; + if (currentActive && currentActive !== this) { // avoid running this logic when there is an active object // this because is possible with shift click and fast clicks, // to rapidly deselect and reselect this object and trigger an enterEdit From c788a0ee55e2acbc964b818976b1376583245446 Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Sat, 29 Sep 2018 15:40:57 +0200 Subject: [PATCH 3/4] test --- test/unit/itext_click_behaviour.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unit/itext_click_behaviour.js b/test/unit/itext_click_behaviour.js index 76220dc428a..cbb1c4b3256 100644 --- a/test/unit/itext_click_behaviour.js +++ b/test/unit/itext_click_behaviour.js @@ -61,6 +61,7 @@ iText.renderCursorOrSelection = function() {}; assert.equal(iText.isEditing, false, 'iText not editing'); iText.canvas = canvas; + canvas._activeObject = null; iText.selected = true; iText.__lastSelected = true; iText.mouseUpHandler({ e: {} }); From b5e75ed8acbc2d07614a8654868dafc0ad92fe47 Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Sat, 29 Sep 2018 15:45:49 +0200 Subject: [PATCH 4/4] added a test --- test/unit/itext_click_behaviour.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/unit/itext_click_behaviour.js b/test/unit/itext_click_behaviour.js index cbb1c4b3256..7a9ce0123b4 100644 --- a/test/unit/itext_click_behaviour.js +++ b/test/unit/itext_click_behaviour.js @@ -68,6 +68,19 @@ assert.equal(iText.isEditing, true, 'iText entered editing'); iText.exitEditing(); }); + QUnit.test('_mouseUpHandler on a selected object does enter edit if there is an activeObject', function(assert) { + var iText = new fabric.IText('test'); + iText.initDelayedCursor = function() {}; + iText.renderCursorOrSelection = function() {}; + assert.equal(iText.isEditing, false, 'iText not editing'); + iText.canvas = canvas; + canvas._activeObject = new fabric.IText('test2'); + iText.selected = true; + iText.__lastSelected = true; + iText.mouseUpHandler({ e: {} }); + assert.equal(iText.isEditing, false, 'iText did not enter editing'); + iText.exitEditing(); + }); QUnit.test('_mouseUpHandler on a selected text in a group DOES NOT enter edit', function(assert) { var iText = new fabric.IText('test'); iText.initDelayedCursor = function() {};