Skip to content

Commit 24e80e0

Browse files
committed
Adjust position in Absolute Mode for children #3770
1 parent a7c42bb commit 24e80e0

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/commands/view/ComponentDrag.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -321,17 +321,31 @@ export default {
321321
const { Canvas } = editor;
322322
const style = target.getStyle();
323323
const position = 'absolute';
324+
const relPos = [position, 'relative'];
324325
onStart && onStart(this._getDragData());
325326
if (isTran) return;
326327

327328
if (style.position !== position) {
328329
let { left, top, width, height } = Canvas.offset(target.getEl());
330+
let parent = target.parent();
331+
let parentRel;
329332

330-
// Check if to center the target to the pointer position
333+
// Check for the relative parent
334+
do {
335+
const pStyle = parent.getStyle();
336+
parentRel = relPos.indexOf(pStyle.position) >= 0 ? parent : null;
337+
parent = parent.parent();
338+
} while (parent && !parentRel);
339+
340+
// Center the target to the pointer position (used in Droppable for Blocks)
331341
if (center) {
332342
const { x, y } = Canvas.getMouseRelativeCanvas(event);
333343
left = x;
334344
top = y;
345+
} else if (parentRel) {
346+
const offsetP = Canvas.offset(parentRel.getEl());
347+
left = left - offsetP.left;
348+
top = top - offsetP.top;
335349
}
336350

337351
this.setPosition({

0 commit comments

Comments
 (0)