From 5615237836f7b64d01268fba6e259e63c068ddf8 Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Sun, 16 Jan 2022 00:53:27 +0100 Subject: [PATCH] feat(fabric.Canvas): fire an extra mouse up for the original control of the initial target (#7612) --- src/canvas.class.js | 1 + src/mixins/canvas_events.mixin.js | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/canvas.class.js b/src/canvas.class.js index 37125356107..6c22317d476 100644 --- a/src/canvas.class.js +++ b/src/canvas.class.js @@ -37,6 +37,7 @@ * @fires dragover * @fires dragenter * @fires dragleave + * @fires drop:before before drop event. same native event. This is added to handle edge cases * @fires drop * @fires after:render at the end of the render process, receives the context in the callback * @fires before:render at start the render process, receives the context in the callback diff --git a/src/mixins/canvas_events.mixin.js b/src/mixins/canvas_events.mixin.js index 4228edda8d3..e7d6b34b2b8 100644 --- a/src/mixins/canvas_events.mixin.js +++ b/src/mixins/canvas_events.mixin.js @@ -462,25 +462,34 @@ ); } } + var corner, pointer; if (target) { + corner = target._findTargetCorner( + this.getPointer(e, true), + fabric.util.isTouchEvent(e) + ); if (target.selectable && target !== this._activeObject && target.activeOn === 'up') { this.setActiveObject(target, e); shouldRender = true; } else { - var corner = target._findTargetCorner( - this.getPointer(e, true), - fabric.util.isTouchEvent(e) - ); var control = target.controls[corner], mouseUpHandler = control && control.getMouseUpHandler(e, target, control); if (mouseUpHandler) { - var pointer = this.getPointer(e); + pointer = this.getPointer(e); mouseUpHandler(e, transform, pointer.x, pointer.y); } } target.isMoving = false; } + // if we are ending up a transform on a different control or a new object + // fire the original mouse up from the corner that started the transform + if (transform && (transform.target !== target || transform.corner !== corner)) { + var originalControl = transform.target && transform.target.controls[transform.corner], + originalMouseUpHandler = originalControl && originalControl.getMouseUpHandler(e, target, control); + pointer = pointer || this.getPointer(e); + originalMouseUpHandler && originalMouseUpHandler(e, transform, pointer.x, pointer.y); + } this._setCursorFromEvent(e, target); this._handleEvent(e, 'up', LEFT_CLICK, isClick); this._groupSelector = null;