mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-02-07 16:11:12 +01:00
Restore date too
This commit is contained in:
parent
d9f67bd8ee
commit
84d15dc453
@ -314,6 +314,20 @@ class Comment {
|
||||
this.#deleted = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore the comment data (used for undo).
|
||||
* @param {Object} data - The comment data to restore.
|
||||
* @param {string} data.text - The comment text.
|
||||
* @param {string|null} data.richText - The rich text content.
|
||||
* @param {Date|null} data.date - The original date.
|
||||
*/
|
||||
restoreData({ text, richText, date }) {
|
||||
this.#text = text;
|
||||
this.#richText = richText;
|
||||
this.#date = date;
|
||||
this.#deleted = false;
|
||||
}
|
||||
|
||||
setInitialText(text, richText = null) {
|
||||
this.#initialText = text;
|
||||
this.data = text;
|
||||
|
||||
@ -1220,9 +1220,14 @@ class AnnotationEditor {
|
||||
};
|
||||
}
|
||||
|
||||
set comment(text) {
|
||||
set comment(value) {
|
||||
this.#comment ||= new Comment(this);
|
||||
this.#comment.data = text;
|
||||
if (typeof value === "object" && value !== null) {
|
||||
// Restore full comment data (used for undo).
|
||||
this.#comment.restoreData(value);
|
||||
} else {
|
||||
this.#comment.data = value;
|
||||
}
|
||||
if (this.hasComment) {
|
||||
this.removeCommentButtonFromToolbar();
|
||||
this.addStandaloneCommentButton();
|
||||
|
||||
@ -1180,11 +1180,11 @@ class AnnotationEditorUIManager {
|
||||
/**
|
||||
* Delete a comment from an editor with undo support.
|
||||
* @param {AnnotationEditor} editor - The editor whose comment to delete.
|
||||
* @param {string} savedComment - The comment text to save for undo.
|
||||
* @param {Object} savedData - The comment data to save for undo.
|
||||
*/
|
||||
deleteComment(editor, savedComment) {
|
||||
deleteComment(editor, savedData) {
|
||||
const undo = () => {
|
||||
editor.comment = savedComment;
|
||||
editor.comment = savedData;
|
||||
};
|
||||
const cmd = () => {
|
||||
this._editorUndoBar?.show(undo, "comment");
|
||||
|
||||
@ -999,6 +999,14 @@ describe("Comment", () => {
|
||||
);
|
||||
|
||||
await page.waitForSelector("#commentPopup", { visible: true });
|
||||
|
||||
// Capture the date before deletion
|
||||
const dateBefore = await page.evaluate(
|
||||
() =>
|
||||
document.querySelector("#commentPopup .commentPopupTime")
|
||||
?.textContent
|
||||
);
|
||||
|
||||
await waitAndClick(page, "button.commentPopupDelete");
|
||||
|
||||
await page.waitForSelector("#editorUndoBar", { visible: true });
|
||||
@ -1016,6 +1024,16 @@ describe("Comment", () => {
|
||||
?.textContent
|
||||
);
|
||||
expect(popupText).withContext(`In ${browserName}`).toEqual(comment);
|
||||
|
||||
// Check that the date is preserved
|
||||
const dateAfter = await page.evaluate(
|
||||
() =>
|
||||
document.querySelector("#commentPopup .commentPopupTime")
|
||||
?.textContent
|
||||
);
|
||||
expect(dateAfter)
|
||||
.withContext(`In ${browserName}`)
|
||||
.toEqual(dateBefore);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
@ -982,11 +982,11 @@ class CommentPopup {
|
||||
},
|
||||
},
|
||||
});
|
||||
const savedComment = this.#editor.comment?.text;
|
||||
const editor = this.#editor;
|
||||
const savedData = editor.comment;
|
||||
this.destroy();
|
||||
if (savedComment) {
|
||||
editor._uiManager.deleteComment(editor, savedComment);
|
||||
if (savedData?.text) {
|
||||
editor._uiManager.deleteComment(editor, savedData);
|
||||
} else {
|
||||
editor.comment = null;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user