Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid enter editing if there is another active object on the canvas #5261

Merged
merged 4 commits into from
Sep 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/mixins/canvas_events.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@
}
this._handleEvent(e, 'down');
// we must renderAll so that we update the visuals
shouldRender && this.requestRenderAll();
(shouldRender || shouldGroup) && this.requestRenderAll();
},

/**
Expand Down
10 changes: 10 additions & 0 deletions src/mixins/itext_click_behavior.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
return;
}

if (this.canvas) {
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
return;
}
}

if (this.__lastSelected && !this.__corner) {
this.selected = false;
this.__lastSelected = false;
Expand Down
14 changes: 14 additions & 0 deletions test/unit/itext_click_behaviour.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,26 @@
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: {} });
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() {};
Expand Down