File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -135,6 +135,10 @@ class Comment {
135135 return this . #deleted || this . #text === "" ;
136136 }
137137
138+ isEmpty ( ) {
139+ return this . #text === null ;
140+ }
141+
138142 hasBeenEdited ( ) {
139143 return this . isDeleted ( ) || this . #text !== this . #initialText;
140144 }
Original file line number Diff line number Diff line change @@ -1103,6 +1103,17 @@ class AnnotationEditor {
11031103 return this . _editToolbar ;
11041104 }
11051105
1106+ addCommentButtonInToolbar ( ) {
1107+ if ( ! this . _editToolbar ) {
1108+ return ;
1109+ }
1110+ this . _editToolbar . addButtonBefore (
1111+ "comment" ,
1112+ this . addCommentButton ( ) ,
1113+ ".deleteButton"
1114+ ) ;
1115+ }
1116+
11061117 removeEditToolbar ( ) {
11071118 if ( ! this . _editToolbar ) {
11081119 return ;
@@ -1214,10 +1225,14 @@ class AnnotationEditor {
12141225 }
12151226
12161227 set comment ( text ) {
1217- if ( ! this . #comment) {
1218- this . #comment = new Comment ( this ) ;
1219- }
1228+ this . #comment ||= new Comment ( this ) ;
12201229 this . #comment. data = text ;
1230+ if ( this . hasComment ) {
1231+ this . addStandaloneCommentButton ( ) ;
1232+ } else {
1233+ this . addCommentButtonInToolbar ( ) ;
1234+ this . removeStandaloneCommentButton ( ) ;
1235+ }
12211236 }
12221237
12231238 setCommentData ( { comment, richText } ) {
@@ -1232,7 +1247,9 @@ class AnnotationEditor {
12321247 }
12331248
12341249 get hasComment ( ) {
1235- return ! ! this . #comment && ! this . #comment. isDeleted ( ) ;
1250+ return (
1251+ ! ! this . #comment && ! this . #comment. isEmpty ( ) && ! this . #comment. isDeleted ( )
1252+ ) ;
12361253 }
12371254
12381255 async editComment ( ) {
Original file line number Diff line number Diff 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 ;
You can’t perform that action at this time.
0 commit comments