From 24e80e0938d27cbf014d14afa9c982f87182e2d7 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Fri, 19 Nov 2021 15:19:24 +0100 Subject: [PATCH] Adjust position in Absolute Mode for children #3770 --- src/commands/view/ComponentDrag.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/commands/view/ComponentDrag.js b/src/commands/view/ComponentDrag.js index 3ebbdd1899..0c5aa1836e 100644 --- a/src/commands/view/ComponentDrag.js +++ b/src/commands/view/ComponentDrag.js @@ -321,17 +321,31 @@ export default { const { Canvas } = editor; const style = target.getStyle(); const position = 'absolute'; + const relPos = [position, 'relative']; onStart && onStart(this._getDragData()); if (isTran) return; if (style.position !== position) { let { left, top, width, height } = Canvas.offset(target.getEl()); + let parent = target.parent(); + let parentRel; - // Check if to center the target to the pointer position + // Check for the relative parent + do { + const pStyle = parent.getStyle(); + parentRel = relPos.indexOf(pStyle.position) >= 0 ? parent : null; + parent = parent.parent(); + } while (parent && !parentRel); + + // Center the target to the pointer position (used in Droppable for Blocks) if (center) { const { x, y } = Canvas.getMouseRelativeCanvas(event); left = x; top = y; + } else if (parentRel) { + const offsetP = Canvas.offset(parentRel.getEl()); + left = left - offsetP.left; + top = top - offsetP.top; } this.setPosition({