Skip to content

Commit

Permalink
Adjust position in Absolute Mode for children #3770
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Nov 19, 2021
1 parent a7c42bb commit 24e80e0
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/commands/view/ComponentDrag.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 24e80e0

Please sign in to comment.