File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -314,6 +314,20 @@ class Comment {
314314 this . #deleted = false ;
315315 }
316316
317+ /**
318+ * Restore the comment data (used for undo).
319+ * @param {Object } data - The comment data to restore.
320+ * @param {string } data.text - The comment text.
321+ * @param {string|null } data.richText - The rich text content.
322+ * @param {Date|null } data.date - The original date.
323+ */
324+ restoreData ( { text, richText, date } ) {
325+ this . #text = text ;
326+ this . #richText = richText ;
327+ this . #date = date ;
328+ this . #deleted = false ;
329+ }
330+
317331 setInitialText ( text , richText = null ) {
318332 this . #initialText = text ;
319333 this . data = text ;
Original file line number Diff line number Diff line change @@ -1220,9 +1220,14 @@ class AnnotationEditor {
12201220 } ;
12211221 }
12221222
1223- set comment ( text ) {
1223+ set comment ( value ) {
12241224 this . #comment ||= new Comment ( this ) ;
1225- this . #comment. data = text ;
1225+ if ( typeof value === "object" && value !== null ) {
1226+ // Restore full comment data (used for undo).
1227+ this . #comment. restoreData ( value ) ;
1228+ } else {
1229+ this . #comment. data = value ;
1230+ }
12261231 if ( this . hasComment ) {
12271232 this . removeCommentButtonFromToolbar ( ) ;
12281233 this . addStandaloneCommentButton ( ) ;
Original file line number Diff line number Diff line change @@ -1180,11 +1180,11 @@ class AnnotationEditorUIManager {
11801180 /**
11811181 * Delete a comment from an editor with undo support.
11821182 * @param {AnnotationEditor } editor - The editor whose comment to delete.
1183- * @param {string } savedComment - The comment text to save for undo.
1183+ * @param {Object } savedData - The comment data to save for undo.
11841184 */
1185- deleteComment ( editor , savedComment ) {
1185+ deleteComment ( editor , savedData ) {
11861186 const undo = ( ) => {
1187- editor . comment = savedComment ;
1187+ editor . comment = savedData ;
11881188 } ;
11891189 const cmd = ( ) => {
11901190 this . _editorUndoBar ?. show ( undo , "comment" ) ;
Original file line number Diff line number Diff line change @@ -999,6 +999,14 @@ describe("Comment", () => {
999999 ) ;
10001000
10011001 await page . waitForSelector ( "#commentPopup" , { visible : true } ) ;
1002+
1003+ // Capture the date before deletion
1004+ const dateBefore = await page . evaluate (
1005+ ( ) =>
1006+ document . querySelector ( "#commentPopup .commentPopupTime" )
1007+ ?. textContent
1008+ ) ;
1009+
10021010 await waitAndClick ( page , "button.commentPopupDelete" ) ;
10031011
10041012 await page . waitForSelector ( "#editorUndoBar" , { visible : true } ) ;
@@ -1016,6 +1024,16 @@ describe("Comment", () => {
10161024 ?. textContent
10171025 ) ;
10181026 expect ( popupText ) . withContext ( `In ${ browserName } ` ) . toEqual ( comment ) ;
1027+
1028+ // Check that the date is preserved
1029+ const dateAfter = await page . evaluate (
1030+ ( ) =>
1031+ document . querySelector ( "#commentPopup .commentPopupTime" )
1032+ ?. textContent
1033+ ) ;
1034+ expect ( dateAfter )
1035+ . withContext ( `In ${ browserName } ` )
1036+ . toEqual ( dateBefore ) ;
10191037 } )
10201038 ) ;
10211039 } ) ;
Original file line number Diff line number Diff line change @@ -982,11 +982,11 @@ class CommentPopup {
982982 } ,
983983 } ,
984984 } ) ;
985- const savedComment = this . #editor. comment ?. text ;
986985 const editor = this . #editor;
986+ const savedData = editor . comment ;
987987 this . destroy ( ) ;
988- if ( savedComment ) {
989- editor . _uiManager . deleteComment ( editor , savedComment ) ;
988+ if ( savedData ?. text ) {
989+ editor . _uiManager . deleteComment ( editor , savedData ) ;
990990 } else {
991991 editor . comment = null ;
992992 }
You can’t perform that action at this time.
0 commit comments