@@ -158,6 +158,8 @@ export class Comment extends CanvasSectionObject {
158158 return ;
159159
160160 var button = L . DomUtil . create ( 'div' , 'annotation-btns-container' , this . sectionProperties . nodeModify ) ;
161+ L . DomEvent . on ( this . sectionProperties . nodeModifyText , 'focus' , this . onFocus , this ) ;
162+ L . DomEvent . on ( this . sectionProperties . nodeReplyText , 'focus' , this . onFocusReply , this ) ;
161163 L . DomEvent . on ( this . sectionProperties . nodeModifyText , 'input' , this . textAreaInput , this ) ;
162164 L . DomEvent . on ( this . sectionProperties . nodeReplyText , 'input' , this . textAreaInput , this ) ;
163165 L . DomEvent . on ( this . sectionProperties . nodeModifyText , 'keydown' , this . textAreaKeyDown , this ) ;
@@ -300,7 +302,6 @@ export class Comment extends CanvasSectionObject {
300302 this . sectionProperties . authorAvatartdImg = tdImg ;
301303 this . sectionProperties . contentAuthor = L . DomUtil . create ( 'div' , 'cool-annotation-content-author' , tdAuthor ) ;
302304 this . sectionProperties . contentDate = L . DomUtil . create ( 'div' , 'cool-annotation-date' , tdAuthor ) ;
303- this . sectionProperties . autoSave = L . DomUtil . create ( 'div' , 'cool-annotation-autosavelabel' , tdAuthor ) ;
304305 }
305306
306307 private createMenu ( ) : void {
@@ -423,8 +424,6 @@ export class Comment extends CanvasSectionObject {
423424 }
424425
425426 private textAreaInput ( ev : any ) : void {
426- this . sectionProperties . autoSave . innerText = '' ;
427-
428427 if ( ev && app . map . _docLayer . _docType === 'text' ) {
429428 // special handling for mentions
430429 this . map ?. mention . handleMentionInput ( ev , this . isNewPara ( ) ) ;
@@ -462,6 +461,14 @@ export class Comment extends CanvasSectionObject {
462461 return '' ;
463462 }
464463
464+ private onFocus ( ) {
465+ this . resetControl ( this . getSaveButton ( ) , _ ( 'Save' ) , 'annotation-button-autosaved' ) ;
466+ }
467+
468+ private onFocusReply ( ) {
469+ this . resetControl ( this . getReplyButton ( ) , _ ( 'Reply' ) , 'annotation-button-autosaved' ) ;
470+ }
471+
465472 private updateContent ( ) : void {
466473 if ( this . sectionProperties . data . html )
467474 this . sectionProperties . contentText . innerHTML = this . sanitize ( this . sectionProperties . data . html ) ;
@@ -1101,7 +1108,6 @@ export class Comment extends CanvasSectionObject {
11011108
11021109 // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
11031110 public onSaveComment ( e : any ) : void {
1104- this . sectionProperties . commentContainerRemoved = true ;
11051111 L . DomEvent . stopPropagation ( e ) ;
11061112 this . removeLastBRTag ( this . sectionProperties . nodeModifyText ) ;
11071113 this . sectionProperties . data . text = this . sectionProperties . nodeModifyText . innerText ;
@@ -1122,6 +1128,43 @@ export class Comment extends CanvasSectionObject {
11221128 brElements [ brElements . length - 1 ] . remove ( ) ;
11231129 }
11241130
1131+ private getSaveButton ( ) : HTMLButtonElement | null {
1132+ return this . sectionProperties . nodeModify . querySelector ( 'input[type="button"][id^="annotation-save-"]' ) ;
1133+ }
1134+
1135+ private getCancelButton ( ) : HTMLButtonElement | null {
1136+ return this . sectionProperties . nodeModify . querySelector ( 'input[type="button"][id^="annotation-cancel-"]' ) ;
1137+ }
1138+
1139+ private getReplyButton ( ) : HTMLButtonElement | null {
1140+ return this . sectionProperties . nodeReply . querySelector ( 'input[type="button"][id^="annotation-reply-"]' ) ;
1141+ }
1142+
1143+ private getCancelReplyButton ( ) : HTMLButtonElement | null {
1144+ return this . sectionProperties . nodeReply . querySelector ( 'input[type="button"][id^="annotation-cancel-reply-"]' ) ;
1145+ }
1146+
1147+ private updateControl (
1148+ button : HTMLButtonElement | null ,
1149+ label : string ,
1150+ className : string
1151+ ) : void {
1152+ if ( button ) {
1153+ button . value = label ;
1154+ button . classList . add ( className ) ;
1155+ }
1156+ }
1157+
1158+ private updateSaveControls ( ) {
1159+ this . updateControl ( this . getSaveButton ( ) , _ ( 'Saved' ) , 'annotation-button-autosaved' ) ;
1160+ this . updateControl ( this . getCancelButton ( ) , _ ( 'Delete' ) , 'annotation-button-delete' ) ;
1161+ }
1162+
1163+ private updateReplyControls ( ) {
1164+ this . updateControl ( this . getReplyButton ( ) , _ ( 'Saved' ) , 'annotation-button-autosaved' ) ;
1165+ this . updateControl ( this . getCancelReplyButton ( ) , _ ( 'Delete' ) , 'annotation-button-delete' ) ;
1166+ }
1167+
11251168 // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
11261169 public onLostFocus ( e : any ) : void {
11271170
@@ -1136,7 +1179,6 @@ export class Comment extends CanvasSectionObject {
11361179 return ;
11371180 }
11381181 if ( ! this . sectionProperties . commentContainerRemoved ) {
1139- this . cachedIsEdit = false ;
11401182 $ ( this . sectionProperties . container ) . removeClass ( 'annotation-active reply-annotation-container modify-annotation-container' ) ;
11411183 this . removeLastBRTag ( this . sectionProperties . nodeModifyText ) ;
11421184 if ( this . sectionProperties . contentText . origText !== this . sectionProperties . nodeModifyText . innerText ||
@@ -1183,6 +1225,27 @@ export class Comment extends CanvasSectionObject {
11831225 }
11841226 }
11851227
1228+ private resetControl (
1229+ button : HTMLButtonElement | null ,
1230+ label : string ,
1231+ className : string
1232+ ) : void {
1233+ if ( button ) {
1234+ button . value = label ;
1235+ button . classList . remove ( className ) ;
1236+ }
1237+ }
1238+
1239+ private resetSaveControls ( ) : void {
1240+ this . resetControl ( this . getSaveButton ( ) , _ ( 'Save' ) , 'annotation-button-autosaved' ) ;
1241+ this . resetControl ( this . getCancelButton ( ) , _ ( 'Cancel' ) , 'annotation-button-delete' ) ;
1242+ }
1243+
1244+ private resetReplyControls ( ) : void {
1245+ this . resetControl ( this . getReplyButton ( ) , _ ( 'Reply' ) , 'annotation-button-autosaved' ) ;
1246+ this . resetControl ( this . getCancelReplyButton ( ) , _ ( 'Cancel' ) , 'annotation-button-delete' ) ;
1247+ }
1248+
11861249 public focus ( ) : void {
11871250 this . sectionProperties . container . classList . add ( 'annotation-active' ) ;
11881251 this . sectionProperties . nodeModifyText . focus ( { focusVisible : true } ) ;
@@ -1198,6 +1261,13 @@ export class Comment extends CanvasSectionObject {
11981261 sel . addRange ( range )
11991262 }
12001263
1264+ this . resetSaveControls ( ) ;
1265+ this . resetReplyControls ( ) ;
1266+ }
1267+
1268+ public focusLost ( ) : void {
1269+ this . updateSaveControls ( ) ;
1270+ this . updateReplyControls ( ) ;
12011271 }
12021272
12031273 public reply ( ) : Comment {
0 commit comments