Skip to content

Commit f5c913b

Browse files
committed
[Editor] Make sure the comment button is at the right place when adding it in the toolbar
1 parent d946de9 commit f5c913b

3 files changed

Lines changed: 43 additions & 7 deletions

File tree

src/display/editor/comment.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ class Comment {
133133
return this.#deleted || this.#text === "";
134134
}
135135

136+
isEmpty() {
137+
return this.#text === null;
138+
}
139+
136140
hasBeenEdited() {
137141
return this.isDeleted() || this.#text !== this.#initialText;
138142
}
@@ -145,7 +149,7 @@ class Comment {
145149
return {
146150
text: this.#text,
147151
date: this.#date,
148-
deleted: this.#deleted,
152+
deleted: this.isDeleted(),
149153
};
150154
}
151155

src/display/editor/editor.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,17 @@ class AnnotationEditor {
11021102
return this._editToolbar;
11031103
}
11041104

1105+
addCommentButtonInToolbar() {
1106+
if (!this._editToolbar) {
1107+
return;
1108+
}
1109+
this._editToolbar.addButtonBefore(
1110+
"comment",
1111+
this.addCommentButton(),
1112+
".deleteButton"
1113+
);
1114+
}
1115+
11051116
removeEditToolbar() {
11061117
if (!this._editToolbar) {
11071118
return;
@@ -1210,10 +1221,14 @@ class AnnotationEditor {
12101221
}
12111222

12121223
set comment(text) {
1213-
if (!this.#comment) {
1214-
this.#comment = new Comment(this);
1215-
}
1224+
this.#comment ||= new Comment(this);
12161225
this.#comment.data = text;
1226+
if (this.hasComment) {
1227+
this.addStandaloneCommentButton();
1228+
} else {
1229+
this.addCommentButtonInToolbar();
1230+
this.removeStandaloneCommentButton();
1231+
}
12171232
}
12181233

12191234
setCommentData(text) {
@@ -1228,7 +1243,9 @@ class AnnotationEditor {
12281243
}
12291244

12301245
get hasComment() {
1231-
return !!this.#comment && !this.#comment.isDeleted();
1246+
return (
1247+
!!this.#comment && !this.#comment.isEmpty() && !this.#comment.isDeleted()
1248+
);
12321249
}
12331250

12341251
async editComment() {

src/display/editor/toolbar.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class EditorToolbar {
158158
this.#altText = altText;
159159
}
160160

161-
addComment(comment) {
161+
addComment(comment, beforeElement = null) {
162162
if (this.#comment) {
163163
return;
164164
}
@@ -167,7 +167,12 @@ class EditorToolbar {
167167
return;
168168
}
169169
this.#addListenersToElement(button);
170-
this.#buttons.append(button, this.#divider);
170+
if (!beforeElement) {
171+
this.#buttons.append(button, this.#divider);
172+
} else {
173+
this.#buttons.insertBefore(button, beforeElement);
174+
this.#buttons.insertBefore(this.#divider, beforeElement);
175+
}
171176
this.#comment = comment;
172177
comment.toolbar = this;
173178
}
@@ -209,6 +214,16 @@ class EditorToolbar {
209214
}
210215
}
211216

217+
async addButtonBefore(name, tool, beforeSelector) {
218+
const beforeElement = this.#buttons.querySelector(beforeSelector);
219+
if (!beforeElement) {
220+
return;
221+
}
222+
if (name === "comment") {
223+
this.addComment(tool, beforeElement);
224+
}
225+
}
226+
212227
updateEditSignatureButton(description) {
213228
if (this.#signatureDescriptionButton) {
214229
this.#signatureDescriptionButton.title = description;

0 commit comments

Comments
 (0)