Skip to content

Commit 764c2e6

Browse files
committed
[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.
1 parent 394fa2c commit 764c2e6

4 files changed

Lines changed: 21 additions & 21 deletions

File tree

src/display/annotation_layer.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2555,6 +2555,10 @@ class PopupElement {
25552555
this.#popupPosition = pos;
25562556
}
25572557

2558+
hasDefaultPopupPosition() {
2559+
return this.#popupPosition === null;
2560+
}
2561+
25582562
get commentButtonPosition() {
25592563
return this.#commentButtonPosition;
25602564
}

src/display/editor/comment.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ class Comment {
111111
this.#popupPosition = pos;
112112
}
113113

114+
hasDefaultPopupPosition() {
115+
return this.#popupPosition === null;
116+
}
117+
114118
removeStandaloneCommentButton() {
115119
this.#commentStandaloneButton?.remove();
116120
this.#commentStandaloneButton = null;

src/display/editor/editor.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,6 +1953,10 @@ class AnnotationEditor {
19531953
this.#comment.commentPopupPositionInLayer = pos;
19541954
}
19551955

1956+
hasDefaultPopupPosition() {
1957+
return this.#comment.hasDefaultPopupPosition();
1958+
}
1959+
19561960
get commentButtonWidth() {
19571961
return this.#comment.commentButtonWidth;
19581962
}

web/comment_manager.js

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class CommentManager {
4646
dateStyle: "long",
4747
});
4848
this.dialogElement = commentDialog.dialog;
49-
this.#dialog = new CommentDialog(commentDialog, overlayManager, ltr);
49+
this.#dialog = new CommentDialog(commentDialog, overlayManager);
5050
this.#popup = new CommentPopup(dateFormat, ltr, this.dialogElement);
5151
this.#sidebar = new CommentSidebar(
5252
sidebar,
@@ -572,19 +572,15 @@ class CommentDialog {
572572

573573
#dialogY = 0;
574574

575-
#isLTR;
576-
577575
constructor(
578576
{ dialog, toolbar, title, textInput, cancelButton, saveButton },
579-
overlayManager,
580-
ltr
577+
overlayManager
581578
) {
582579
this.#dialog = dialog;
583580
this.#textInput = textInput;
584581
this.#overlayManager = overlayManager;
585582
this.#saveButton = saveButton;
586583
this.#title = title;
587-
this.#isLTR = ltr;
588584

589585
const finishBound = this.#finish.bind(this);
590586
dialog.addEventListener("close", finishBound);
@@ -686,17 +682,6 @@ class CommentDialog {
686682
}
687683
this.#uiManager?.removeEditListeners();
688684
this.#saveButton.disabled = true;
689-
const parentDimensions = options?.parentDimensions;
690-
if (
691-
parentDimensions &&
692-
((this.#isLTR &&
693-
posX + this._dialogWidth >
694-
parentDimensions.x + parentDimensions.width) ||
695-
(!this.#isLTR && posX - this._dialogWidth < parentDimensions.x))
696-
) {
697-
const buttonWidth = this.#editor.commentButtonWidth;
698-
posX -= this._dialogWidth - buttonWidth * parentDimensions.width;
699-
}
700685

701686
this.#setPosition(posX, posY);
702687

@@ -903,7 +888,7 @@ class CommentPopup {
903888
this.#setPosition(
904889
this.#posX + (x - this.#prevDragX) / parentWidth,
905890
this.#posY + (y - this.#prevDragY) / parentHeight,
906-
/* isDragging = */ true
891+
/* correctPosition = */ false
907892
);
908893
this.#prevDragX = x;
909894
this.#prevDragY = y;
@@ -1019,7 +1004,10 @@ class CommentPopup {
10191004
this.#time.textContent = this.#dateFormat.format(
10201005
PDFDateString.toDateObject(modificationDate || creationDate)
10211006
);
1022-
this.#setPosition(...editor.commentPopupPosition);
1007+
this.#setPosition(
1008+
...editor.commentPopupPosition,
1009+
/* correctPosition = */ editor.hasDefaultPopupPosition()
1010+
);
10231011
editor.elementBeforePopup.after(container);
10241012
container.addEventListener(
10251013
"focus",
@@ -1033,8 +1021,8 @@ class CommentPopup {
10331021
}
10341022
}
10351023

1036-
#setPosition(x, y, isDragging = false) {
1037-
if (isDragging) {
1024+
#setPosition(x, y, correctPosition = true) {
1025+
if (!correctPosition) {
10381026
this.#editor.commentPopupPosition = [x, y];
10391027
} else {
10401028
const widthRatio =

0 commit comments

Comments
 (0)