Merge pull request #20245 from calixteman/comment_richtext

[Editor] Add the dates and rich text if any to the editors in order to use them when displaying the popup
This commit is contained in:
calixteman 2025-09-08 22:23:03 +02:00 committed by GitHub
commit 17a27806c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 80 additions and 23 deletions

View File

@ -26,6 +26,8 @@ class Comment {
#initialText = null; #initialText = null;
#richText = null;
#text = null; #text = null;
#date = null; #date = null;
@ -144,8 +146,9 @@ class Comment {
get data() { get data() {
return { return {
text: this.#text, text: this.#text,
richText: this.#richText,
date: this.#date, date: this.#date,
deleted: this.#deleted, deleted: this.isDeleted(),
}; };
} }
@ -153,6 +156,9 @@ class Comment {
* Set the comment data. * Set the comment data.
*/ */
set data(text) { set data(text) {
if (text !== this.#text) {
this.#richText = null;
}
if (text === null) { if (text === null) {
this.#text = ""; this.#text = "";
this.#deleted = true; this.#deleted = true;
@ -163,9 +169,11 @@ class Comment {
this.#deleted = false; this.#deleted = false;
} }
setInitialText(text) { setInitialText(text, richText = null) {
this.#initialText = text; this.#initialText = text;
this.data = text; this.data = text;
this.#date = null;
this.#richText = richText;
} }
shown() {} shown() {}
@ -176,6 +184,7 @@ class Comment {
this.#commentStandaloneButton?.remove(); this.#commentStandaloneButton?.remove();
this.#commentStandaloneButton = null; this.#commentStandaloneButton = null;
this.#text = ""; this.#text = "";
this.#richText = null;
this.#date = null; this.#date = null;
this.#editor = null; this.#editor = null;
this.#commentWasFromKeyBoard = false; this.#commentWasFromKeyBoard = false;

View File

@ -191,7 +191,8 @@ class AnnotationEditor {
this._initialOptions.isCentered = parameters.isCentered; this._initialOptions.isCentered = parameters.isCentered;
this._structTreeParentId = null; this._structTreeParentId = null;
this.annotationElementId = parameters.annotationElementId || null; this.annotationElementId = parameters.annotationElementId || null;
this.creationDate = new Date(); this.creationDate = parameters.creationDate || new Date();
this.modificationDate = parameters.modificationDate || null;
const { const {
rotation, rotation,
@ -1200,11 +1201,14 @@ class AnnotationEditor {
} }
get comment() { get comment() {
const comment = this.#comment; const {
data: { richText, text, date, deleted },
} = this.#comment;
return { return {
text: comment.data.text, text,
date: comment.data.date, richText,
deleted: comment.isDeleted(), date,
deleted,
color: this.commentColor, color: this.commentColor,
}; };
} }
@ -1216,11 +1220,11 @@ class AnnotationEditor {
this.#comment.data = text; this.#comment.data = text;
} }
setCommentData(text) { setCommentData({ comment, richText }) {
if (!this.#comment) { if (!this.#comment) {
this.#comment = new Comment(this); this.#comment = new Comment(this);
} }
this.#comment.setInitialText(text); this.#comment.setInitialText(comment, richText);
} }
get hasEditedComment() { get hasEditedComment() {
@ -1611,13 +1615,22 @@ class AnnotationEditor {
} }
getData() { getData() {
const {
comment: { text: str, date, deleted, richText },
uid: id,
pageIndex,
creationDate,
modificationDate,
} = this;
return { return {
id: this.uid, id,
pageIndex: this.pageIndex, pageIndex,
rect: this.getPDFRect(), rect: this.getPDFRect(),
contentsObj: { str: this.comment.text }, richText,
creationDate: this.creationDate, contentsObj: { str },
popupRef: !this.#comment.isDeleted(), creationDate,
modificationDate: date || modificationDate,
popupRef: !deleted,
}; };
} }
@ -1774,6 +1787,8 @@ class AnnotationEditor {
id: parent.getNextId(), id: parent.getNextId(),
uiManager, uiManager,
annotationElementId: data.annotationElementId, annotationElementId: data.annotationElementId,
creationDate: data.creationDate,
modificationDate: data.modificationDate,
}); });
editor.rotation = data.rotation; editor.rotation = data.rotation;
editor.#accessibilityData = data.accessibilityData; editor.#accessibilityData = data.accessibilityData;

View File

@ -781,7 +781,10 @@ class FreeTextEditor extends AnnotationEditor {
rotation, rotation,
id, id,
popupRef, popupRef,
richText,
contentsObj, contentsObj,
creationDate,
modificationDate,
}, },
textContent, textContent,
textPosition, textPosition,
@ -809,6 +812,9 @@ class FreeTextEditor extends AnnotationEditor {
deleted: false, deleted: false,
popupRef, popupRef,
comment: contentsObj?.str || null, comment: contentsObj?.str || null,
richText,
creationDate,
modificationDate,
}; };
} }
const editor = await super.deserialize(data, parent, uiManager); const editor = await super.deserialize(data, parent, uiManager);
@ -817,7 +823,7 @@ class FreeTextEditor extends AnnotationEditor {
editor.#content = FreeTextEditor.#deserializeContent(data.value); editor.#content = FreeTextEditor.#deserializeContent(data.value);
editor._initialData = initialData; editor._initialData = initialData;
if (data.comment) { if (data.comment) {
editor.setCommentData(data.comment); editor.setCommentData(data);
} }
return editor; return editor;

View File

@ -151,10 +151,6 @@ class HighlightEditor extends AnnotationEditor {
}; };
} }
get commentColor() {
return this.color;
}
static computeTelemetryFinalData(data) { static computeTelemetryFinalData(data) {
// We want to know how many colors have been used. // We want to know how many colors have been used.
return { numberOfColors: data.get("color").size }; return { numberOfColors: data.get("color").size };
@ -891,7 +887,10 @@ class HighlightEditor extends AnnotationEditor {
color, color,
opacity, opacity,
popupRef, popupRef,
richText,
contentsObj, contentsObj,
creationDate,
modificationDate,
}, },
parent: { parent: {
page: { pageNumber }, page: { pageNumber },
@ -910,7 +909,10 @@ class HighlightEditor extends AnnotationEditor {
id, id,
deleted: false, deleted: false,
popupRef, popupRef,
richText,
comment: contentsObj?.str || null, comment: contentsObj?.str || null,
creationDate,
modificationDate,
}; };
} else if (data instanceof InkAnnotationElement) { } else if (data instanceof InkAnnotationElement) {
const { const {
@ -922,7 +924,10 @@ class HighlightEditor extends AnnotationEditor {
color, color,
borderStyle: { rawWidth: thickness }, borderStyle: { rawWidth: thickness },
popupRef, popupRef,
richText,
contentsObj, contentsObj,
creationDate,
modificationDate,
}, },
parent: { parent: {
page: { pageNumber }, page: { pageNumber },
@ -941,7 +946,10 @@ class HighlightEditor extends AnnotationEditor {
id, id,
deleted: false, deleted: false,
popupRef, popupRef,
richText,
comment: contentsObj?.str || null, comment: contentsObj?.str || null,
creationDate,
modificationDate,
}; };
} }
@ -955,7 +963,7 @@ class HighlightEditor extends AnnotationEditor {
} }
editor._initialData = initialData; editor._initialData = initialData;
if (data.comment) { if (data.comment) {
editor.setCommentData(data.comment); editor.setCommentData(data);
} }
const [pageWidth, pageHeight] = editor.pageDimensions; const [pageWidth, pageHeight] = editor.pageDimensions;

View File

@ -150,7 +150,10 @@ class InkEditor extends DrawingEditor {
opacity, opacity,
borderStyle: { rawWidth: thickness }, borderStyle: { rawWidth: thickness },
popupRef, popupRef,
richText,
contentsObj, contentsObj,
creationDate,
modificationDate,
}, },
parent: { parent: {
page: { pageNumber }, page: { pageNumber },
@ -170,14 +173,17 @@ class InkEditor extends DrawingEditor {
id, id,
deleted: false, deleted: false,
popupRef, popupRef,
richText,
comment: contentsObj?.str || null, comment: contentsObj?.str || null,
creationDate,
modificationDate,
}; };
} }
const editor = await super.deserialize(data, parent, uiManager); const editor = await super.deserialize(data, parent, uiManager);
editor._initialData = initialData; editor._initialData = initialData;
if (data.comment) { if (data.comment) {
editor.setCommentData(data.comment); editor.setCommentData(data);
} }
return editor; return editor;

View File

@ -751,7 +751,17 @@ class StampEditor extends AnnotationEditor {
let missingCanvas = false; let missingCanvas = false;
if (data instanceof StampAnnotationElement) { if (data instanceof StampAnnotationElement) {
const { const {
data: { rect, rotation, id, structParent, popupRef, contentsObj }, data: {
rect,
rotation,
id,
structParent,
popupRef,
richText,
contentsObj,
creationDate,
modificationDate,
},
container, container,
parent: { parent: {
page: { pageNumber }, page: { pageNumber },
@ -795,7 +805,10 @@ class StampEditor extends AnnotationEditor {
isSvg: false, isSvg: false,
structParent, structParent,
popupRef, popupRef,
richText,
comment: contentsObj?.str || null, comment: contentsObj?.str || null,
creationDate,
modificationDate,
}; };
} }
const editor = await super.deserialize(data, parent, uiManager); const editor = await super.deserialize(data, parent, uiManager);
@ -823,7 +836,7 @@ class StampEditor extends AnnotationEditor {
} }
editor._initialData = initialData; editor._initialData = initialData;
if (data.comment) { if (data.comment) {
editor.setCommentData(data.comment); editor.setCommentData(data);
} }
// No need to be add in the undo stack if the editor is created from an // No need to be add in the undo stack if the editor is created from an
// existing one. // existing one.