Skip to content

Commit

Permalink
Merge pull request #16944 from calixteman/move_dom_after_position
Browse files Browse the repository at this point in the history
[Editor] Move an editor in the DOM just after having moved it on the screen
  • Loading branch information
calixteman authored Sep 13, 2023
2 parents b157822 + 720963b commit 920e51a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
4 changes: 1 addition & 3 deletions src/display/editor/annotation_editor_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,8 @@ class AnnotationEditorLayer {
editor.isAttachedToDOM = true;
}

// The editor must have the right position before being moved in the DOM.
// The editor will be correctly moved into the DOM (see fixAndSetPosition).
editor.fixAndSetPosition();
this.moveEditorInDOM(editor);

editor.onceAdded();
this.#uiManager.addToAnnotationStorage(editor);
}
Expand Down
17 changes: 8 additions & 9 deletions src/display/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@ class AnnotationEditor {
*/
translateInPage(x, y) {
this.#translate(this.pageDimensions, x, y);
this.moveInDOM();
this.div.scrollIntoView({ block: "nearest" });
}

Expand Down Expand Up @@ -398,11 +397,14 @@ class AnnotationEditor {
break;
}

this.x = x / pageWidth;
this.y = y / pageHeight;
this.x = x /= pageWidth;
this.y = y /= pageHeight;

this.div.style.left = `${(100 * this.x).toFixed(2)}%`;
this.div.style.top = `${(100 * this.y).toFixed(2)}%`;
const { style } = this.div;
style.left = `${(100 * x).toFixed(2)}%`;
style.top = `${(100 * y).toFixed(2)}%`;

this.moveInDOM();
}

static #rotatePoint(x, y, angle) {
Expand Down Expand Up @@ -600,7 +602,6 @@ class AnnotationEditor {
const [parentWidth, parentHeight] = this.parentDimensions;
this.setDims(parentWidth * newWidth, parentHeight * newHeight);
this.fixAndSetPosition();
this.moveInDOM();
},
undo: () => {
this.width = savedWidth;
Expand All @@ -610,7 +611,6 @@ class AnnotationEditor {
const [parentWidth, parentHeight] = this.parentDimensions;
this.setDims(parentWidth * savedWidth, parentHeight * savedHeight);
this.fixAndSetPosition();
this.moveInDOM();
},
mustExec: true,
});
Expand Down Expand Up @@ -856,15 +856,14 @@ class AnnotationEditor {
}

moveInDOM() {
this.parent.moveEditorInDOM(this);
this.parent?.moveEditorInDOM(this);
}

_setParentAndPosition(parent, x, y) {
parent.changeParent(this);
this.x = x;
this.y = y;
this.fixAndSetPosition();
this.moveInDOM();
}

/**
Expand Down

0 comments on commit 920e51a

Please sign in to comment.