[Editor] FreeText annotations aren't supposed to have an attached popup so disable commenting for them (bug 1995028)

This commit is contained in:
Calixte Denizet 2025-10-17 18:33:15 +02:00
parent 928a758811
commit 18a7a82c29
4 changed files with 72 additions and 6 deletions

View File

@ -188,6 +188,7 @@ class AnnotationEditor {
this.annotationElementId = parameters.annotationElementId || null; this.annotationElementId = parameters.annotationElementId || null;
this.creationDate = parameters.creationDate || new Date(); this.creationDate = parameters.creationDate || new Date();
this.modificationDate = parameters.modificationDate || null; this.modificationDate = parameters.modificationDate || null;
this.canAddComment = true;
const { const {
rotation, rotation,
@ -1173,7 +1174,7 @@ class AnnotationEditor {
} }
addCommentButton() { addCommentButton() {
return (this.#comment ||= new Comment(this)); return this.canAddComment ? (this.#comment ||= new Comment(this)) : null;
} }
addStandaloneCommentButton() { addStandaloneCommentButton() {
@ -1991,7 +1992,7 @@ class AnnotationEditor {
} }
setCommentButtonStates(options) { setCommentButtonStates(options) {
this.#comment.setCommentButtonStates(options); this.#comment?.setCommentButtonStates(options);
} }
/** /**

View File

@ -135,6 +135,7 @@ class FreeTextEditor extends AnnotationEditor {
if (!this.annotationElementId) { if (!this.annotationElementId) {
this._uiManager.a11yAlert("pdfjs-editor-freetext-added-alert"); this._uiManager.a11yAlert("pdfjs-editor-freetext-added-alert");
} }
this.canAddComment = false;
} }
/** @inheritdoc */ /** @inheritdoc */

View File

@ -211,24 +211,35 @@ class EditorToolbar {
async addButton(name, tool) { async addButton(name, tool) {
switch (name) { switch (name) {
case "colorPicker": case "colorPicker":
if (tool) {
this.addColorPicker(tool); this.addColorPicker(tool);
}
break; break;
case "altText": case "altText":
if (tool) {
await this.addAltText(tool); await this.addAltText(tool);
}
break; break;
case "editSignature": case "editSignature":
if (tool) {
await this.addEditSignatureButton(tool); await this.addEditSignatureButton(tool);
}
break; break;
case "delete": case "delete":
this.addDeleteButton(); this.addDeleteButton();
break; break;
case "comment": case "comment":
if (tool) {
this.addComment(tool); this.addComment(tool);
}
break; break;
} }
} }
async addButtonBefore(name, tool, beforeSelector) { async addButtonBefore(name, tool, beforeSelector) {
if (!tool && name === "comment") {
return;
}
const beforeElement = this.#buttons.querySelector(beforeSelector); const beforeElement = this.#buttons.querySelector(beforeSelector);
if (!beforeElement) { if (!beforeElement) {
return; return;

View File

@ -27,11 +27,13 @@ import {
switchToEditor, switchToEditor,
waitAndClick, waitAndClick,
waitForSerialized, waitForSerialized,
waitForTimeout,
} from "./test_utils.mjs"; } from "./test_utils.mjs";
const switchToHighlight = switchToEditor.bind(null, "Highlight"); const switchToHighlight = switchToEditor.bind(null, "Highlight");
const switchToStamp = switchToEditor.bind(null, "Stamp"); const switchToStamp = switchToEditor.bind(null, "Stamp");
const switchToComment = switchToEditor.bind(null, "Comment"); const switchToComment = switchToEditor.bind(null, "Comment");
const switchToFreeText = switchToEditor.bind(null, "FreeText");
const highlightSpan = async (page, pageIndex, text) => { const highlightSpan = async (page, pageIndex, text) => {
const rect = await getSpanRectFromText(page, pageIndex, text); const rect = await getSpanRectFromText(page, pageIndex, text);
@ -838,4 +840,55 @@ describe("Comment", () => {
); );
}); });
}); });
describe("FreeText annotation doesn't have a popup (bug 1995028)", () => {
let pages;
beforeEach(async () => {
pages = await loadAndWait(
"empty.pdf",
".annotationEditorLayer",
"page-fit",
null,
{ enableComment: true }
);
});
afterEach(async () => {
await closePages(pages);
});
it("must check that comment button isn't in the annotation toolbar", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await switchToFreeText(page);
const rect = await getRect(page, ".annotationEditorLayer");
const editorSelector = getEditorSelector(0);
const data = "Hello PDF.js World !!";
await page.mouse.click(rect.x + 100, rect.y + 100);
await page.waitForSelector(editorSelector, { visible: true });
await page.type(`${editorSelector} .internal`, data);
await page.keyboard.press("Escape");
await page.waitForSelector(`${editorSelector} .editToolbar`, {
visible: true,
});
// We want to be sure that the comment button isn't rendered.
// eslint-disable-next-line no-restricted-syntax
await waitForTimeout(100);
const hasCommentButton = await page.evaluate(
selector =>
!!document.querySelector(
`${selector} .editToolbar button.comment`
),
editorSelector
);
expect(hasCommentButton).withContext(`In ${browserName}`).toBe(false);
})
);
});
});
}); });