From cdaa5c5781bec0efa7869ee7710a1c211c5c6f3f Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Thu, 3 Oct 2019 08:27:50 +0200 Subject: [PATCH] Fix component moving --- src/canvas/index.js | 4 ++-- src/canvas/view/CanvasView.js | 21 ++++++++++++--------- src/utils/Sorter.js | 7 +++++-- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/canvas/index.js b/src/canvas/index.js index 2ba393213..897fac633 100644 --- a/src/canvas/index.js +++ b/src/canvas/index.js @@ -440,9 +440,9 @@ export default () => { * @return {Object} * @private */ - getMouseRelativeCanvas(ev) { + getMouseRelativeCanvas(ev, opts) { const zoom = this.getZoomDecimal(); - const { top, left } = CanvasView.getPosition(); + const { top, left } = CanvasView.getPosition(opts); return { y: ev.clientY * zoom + top, diff --git a/src/canvas/view/CanvasView.js b/src/canvas/view/CanvasView.js index d1b116b03..bebe521e0 100644 --- a/src/canvas/view/CanvasView.js +++ b/src/canvas/view/CanvasView.js @@ -329,12 +329,14 @@ export default Backbone.View.extend({ * @param {HTMLElement} el * @return {Object} */ - offset(el) { - var rect = getElRect(el); - var docBody = el.ownerDocument.body; + offset(el, opts = {}) { + const rect = getElRect(el); + const docBody = el.ownerDocument.body; + const { noScroll } = opts; + return { - top: rect.top + docBody.scrollTop, - left: rect.left + docBody.scrollLeft, + top: rect.top + (noScroll ? 0 : docBody.scrollTop), + left: rect.left + (noScroll ? 0 : docBody.scrollLeft), width: rect.width, height: rect.height }; @@ -380,7 +382,7 @@ export default Backbone.View.extend({ var opt = opts || {}; var frmOff = this.getFrameOffset(); var cvsOff = this.getCanvasOffset(); - var eo = this.offset(el); + var eo = this.offset(el, opts); var frmTop = opt.avoidFrameOffset ? 0 : frmOff.top; var frmLeft = opt.avoidFrameOffset ? 0 : frmOff.left; @@ -424,17 +426,18 @@ export default Backbone.View.extend({ * @return {Object} obj Position object * @private */ - getPosition() { + getPosition(opts = {}) { const doc = this.frame.el.contentDocument; if (!doc) return; const bEl = doc.body; const zoom = this.getZoom(); const fo = this.getFrameOffset(); const co = this.getCanvasOffset(); + const { noScroll } = opts; return { - top: fo.top + bEl.scrollTop * zoom - co.top, - left: fo.left + bEl.scrollLeft * zoom - co.left, + top: fo.top + (noScroll ? 0 : bEl.scrollTop) * zoom - co.top, + left: fo.left + (noScroll ? 0 : bEl.scrollLeft) * zoom - co.left, width: co.width, height: co.height }; diff --git a/src/utils/Sorter.js b/src/utils/Sorter.js index 6a0843fe3..b5b60c7eb 100644 --- a/src/utils/Sorter.js +++ b/src/utils/Sorter.js @@ -306,6 +306,7 @@ export default Backbone.View.extend({ let srcModel; let plh = this.plh; this.dropModel = null; + this.target = null; this.moved = 0; // Check if the start element is a valid one, if not get the @@ -433,7 +434,9 @@ export default Backbone.View.extend({ var rX = e.pageX - this.elL + this.el.scrollLeft; if (this.canvasRelative && em) { - var mousePos = em.get('Canvas').getMouseRelativeCanvas(e); + const mousePos = em + .get('Canvas') + .getMouseRelativeCanvas(e, { noScroll: 1 }); rX = mousePos.x; rY = mousePos.y; } @@ -796,7 +799,7 @@ export default Backbone.View.extend({ if (canvasRelative && em) { const canvas = em.get('Canvas'); - const pos = canvas.getElementPos(el); + const pos = canvas.getElementPos(el, { noScroll: 1 }); const elOffsets = canvas.getElementOffsets(el); top = pos.top - elOffsets.marginTop; left = pos.left - elOffsets.marginLeft;