[Editor] Fix the position of the comment popup and its dialog

Only fix the popup position if the user didn't change it.
And don't adjust the dialog position since it should have the same as the popup.
This commit is contained in:
Calixte Denizet 2025-09-15 21:26:23 +02:00
parent 394fa2c184
commit 764c2e639c
4 changed files with 21 additions and 21 deletions

View File

@ -2555,6 +2555,10 @@ class PopupElement {
this.#popupPosition = pos; this.#popupPosition = pos;
} }
hasDefaultPopupPosition() {
return this.#popupPosition === null;
}
get commentButtonPosition() { get commentButtonPosition() {
return this.#commentButtonPosition; return this.#commentButtonPosition;
} }

View File

@ -111,6 +111,10 @@ class Comment {
this.#popupPosition = pos; this.#popupPosition = pos;
} }
hasDefaultPopupPosition() {
return this.#popupPosition === null;
}
removeStandaloneCommentButton() { removeStandaloneCommentButton() {
this.#commentStandaloneButton?.remove(); this.#commentStandaloneButton?.remove();
this.#commentStandaloneButton = null; this.#commentStandaloneButton = null;

View File

@ -1953,6 +1953,10 @@ class AnnotationEditor {
this.#comment.commentPopupPositionInLayer = pos; this.#comment.commentPopupPositionInLayer = pos;
} }
hasDefaultPopupPosition() {
return this.#comment.hasDefaultPopupPosition();
}
get commentButtonWidth() { get commentButtonWidth() {
return this.#comment.commentButtonWidth; return this.#comment.commentButtonWidth;
} }

View File

@ -46,7 +46,7 @@ class CommentManager {
dateStyle: "long", dateStyle: "long",
}); });
this.dialogElement = commentDialog.dialog; this.dialogElement = commentDialog.dialog;
this.#dialog = new CommentDialog(commentDialog, overlayManager, ltr); this.#dialog = new CommentDialog(commentDialog, overlayManager);
this.#popup = new CommentPopup(dateFormat, ltr, this.dialogElement); this.#popup = new CommentPopup(dateFormat, ltr, this.dialogElement);
this.#sidebar = new CommentSidebar( this.#sidebar = new CommentSidebar(
sidebar, sidebar,
@ -572,19 +572,15 @@ class CommentDialog {
#dialogY = 0; #dialogY = 0;
#isLTR;
constructor( constructor(
{ dialog, toolbar, title, textInput, cancelButton, saveButton }, { dialog, toolbar, title, textInput, cancelButton, saveButton },
overlayManager, overlayManager
ltr
) { ) {
this.#dialog = dialog; this.#dialog = dialog;
this.#textInput = textInput; this.#textInput = textInput;
this.#overlayManager = overlayManager; this.#overlayManager = overlayManager;
this.#saveButton = saveButton; this.#saveButton = saveButton;
this.#title = title; this.#title = title;
this.#isLTR = ltr;
const finishBound = this.#finish.bind(this); const finishBound = this.#finish.bind(this);
dialog.addEventListener("close", finishBound); dialog.addEventListener("close", finishBound);
@ -686,17 +682,6 @@ class CommentDialog {
} }
this.#uiManager?.removeEditListeners(); this.#uiManager?.removeEditListeners();
this.#saveButton.disabled = true; this.#saveButton.disabled = true;
const parentDimensions = options?.parentDimensions;
if (
parentDimensions &&
((this.#isLTR &&
posX + this._dialogWidth >
parentDimensions.x + parentDimensions.width) ||
(!this.#isLTR && posX - this._dialogWidth < parentDimensions.x))
) {
const buttonWidth = this.#editor.commentButtonWidth;
posX -= this._dialogWidth - buttonWidth * parentDimensions.width;
}
this.#setPosition(posX, posY); this.#setPosition(posX, posY);
@ -903,7 +888,7 @@ class CommentPopup {
this.#setPosition( this.#setPosition(
this.#posX + (x - this.#prevDragX) / parentWidth, this.#posX + (x - this.#prevDragX) / parentWidth,
this.#posY + (y - this.#prevDragY) / parentHeight, this.#posY + (y - this.#prevDragY) / parentHeight,
/* isDragging = */ true /* correctPosition = */ false
); );
this.#prevDragX = x; this.#prevDragX = x;
this.#prevDragY = y; this.#prevDragY = y;
@ -1019,7 +1004,10 @@ class CommentPopup {
this.#time.textContent = this.#dateFormat.format( this.#time.textContent = this.#dateFormat.format(
PDFDateString.toDateObject(modificationDate || creationDate) PDFDateString.toDateObject(modificationDate || creationDate)
); );
this.#setPosition(...editor.commentPopupPosition); this.#setPosition(
...editor.commentPopupPosition,
/* correctPosition = */ editor.hasDefaultPopupPosition()
);
editor.elementBeforePopup.after(container); editor.elementBeforePopup.after(container);
container.addEventListener( container.addEventListener(
"focus", "focus",
@ -1033,8 +1021,8 @@ class CommentPopup {
} }
} }
#setPosition(x, y, isDragging = false) { #setPosition(x, y, correctPosition = true) {
if (isDragging) { if (!correctPosition) {
this.#editor.commentPopupPosition = [x, y]; this.#editor.commentPopupPosition = [x, y];
} else { } else {
const widthRatio = const widthRatio =