Merge pull request #20248 from calixteman/toolbar_button_position

[Editor] Make sure the comment button is at the right place when adding it in the toolbar
This commit is contained in:
calixteman 2025-09-08 23:06:02 +02:00 committed by GitHub
commit d009c434f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 42 additions and 6 deletions

View File

@ -135,6 +135,10 @@ class Comment {
return this.#deleted || this.#text === ""; return this.#deleted || this.#text === "";
} }
isEmpty() {
return this.#text === null;
}
hasBeenEdited() { hasBeenEdited() {
return this.isDeleted() || this.#text !== this.#initialText; return this.isDeleted() || this.#text !== this.#initialText;
} }

View File

@ -1103,6 +1103,17 @@ class AnnotationEditor {
return this._editToolbar; return this._editToolbar;
} }
addCommentButtonInToolbar() {
if (!this._editToolbar) {
return;
}
this._editToolbar.addButtonBefore(
"comment",
this.addCommentButton(),
".deleteButton"
);
}
removeEditToolbar() { removeEditToolbar() {
if (!this._editToolbar) { if (!this._editToolbar) {
return; return;
@ -1214,10 +1225,14 @@ class AnnotationEditor {
} }
set comment(text) { set comment(text) {
if (!this.#comment) { this.#comment ||= new Comment(this);
this.#comment = new Comment(this);
}
this.#comment.data = text; this.#comment.data = text;
if (this.hasComment) {
this.addStandaloneCommentButton();
} else {
this.addCommentButtonInToolbar();
this.removeStandaloneCommentButton();
}
} }
setCommentData({ comment, richText }) { setCommentData({ comment, richText }) {
@ -1232,7 +1247,9 @@ class AnnotationEditor {
} }
get hasComment() { get hasComment() {
return !!this.#comment && !this.#comment.isDeleted(); return (
!!this.#comment && !this.#comment.isEmpty() && !this.#comment.isDeleted()
);
} }
async editComment() { async editComment() {

View File

@ -158,7 +158,7 @@ class EditorToolbar {
this.#altText = altText; this.#altText = altText;
} }
addComment(comment) { addComment(comment, beforeElement = null) {
if (this.#comment) { if (this.#comment) {
return; return;
} }
@ -167,7 +167,12 @@ class EditorToolbar {
return; return;
} }
this.#addListenersToElement(button); this.#addListenersToElement(button);
this.#buttons.append(button, this.#divider); if (!beforeElement) {
this.#buttons.append(button, this.#divider);
} else {
this.#buttons.insertBefore(button, beforeElement);
this.#buttons.insertBefore(this.#divider, beforeElement);
}
this.#comment = comment; this.#comment = comment;
comment.toolbar = this; comment.toolbar = this;
} }
@ -209,6 +214,16 @@ class EditorToolbar {
} }
} }
async addButtonBefore(name, tool, beforeSelector) {
const beforeElement = this.#buttons.querySelector(beforeSelector);
if (!beforeElement) {
return;
}
if (name === "comment") {
this.addComment(tool, beforeElement);
}
}
updateEditSignatureButton(description) { updateEditSignatureButton(description) {
if (this.#signatureDescriptionButton) { if (this.#signatureDescriptionButton) {
this.#signatureDescriptionButton.title = description; this.#signatureDescriptionButton.title = description;