1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

[Editor] Make highlight annotations editable (bug 1883884)

The goal of this patch is to be able to edit existing highlight annotations.
This commit is contained in:
Calixte Denizet 2024-07-11 22:31:55 +02:00
parent 0676ea19cf
commit a62ceedb69
12 changed files with 574 additions and 28 deletions

View file

@ -32,6 +32,9 @@ import {
scrollIntoView,
setCaretAt,
switchToEditor,
waitAndClick,
waitForAnnotationModeChanged,
waitForSelectedEditor,
waitForSerialized,
} from "./test_utils.mjs";
@ -1921,4 +1924,100 @@ describe("Highlight Editor", () => {
);
});
});
describe("Highlight (edit existing in double clicking on it)", () => {
let pages;
beforeAll(async () => {
pages = await loadAndWait(
"highlights.pdf",
".annotationEditorLayer",
null,
null,
{
highlightEditorColors:
"yellow=#FFFF00,green=#00FF00,blue=#0000FF,pink=#FF00FF,red=#FF0102",
}
);
});
afterAll(async () => {
await closePages(pages);
});
it("must change the color of an highlight", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
const modeChangedHandle = await waitForAnnotationModeChanged(page);
await waitAndClick(page, "[data-annotation-id='687R']", { count: 2 });
await awaitPromise(modeChangedHandle);
await page.waitForSelector("#highlightParamsToolbarContainer");
const editorSelector = getEditorSelector(5);
await page.waitForSelector(editorSelector);
await waitAndClick(
page,
`${editorSelector} .editToolbar button.colorPicker`
);
await waitAndClick(
page,
`${editorSelector} .editToolbar button[title = "Red"]`
);
await page.waitForSelector(
`.page[data-page-number = "1"] svg.highlight[fill = "#FF0102"]`
);
})
);
});
});
describe("Free Highlight (edit existing in double clicking on it)", () => {
let pages;
beforeAll(async () => {
pages = await loadAndWait(
"highlights.pdf",
".annotationEditorLayer",
null,
null,
{
highlightEditorColors:
"yellow=#FFFF00,green=#00FF00,blue=#0000FF,pink=#FF00FF,red=#FF0102",
}
);
});
afterAll(async () => {
await closePages(pages);
});
it("must change the color of a free highlight", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
const modeChangedHandle = await waitForAnnotationModeChanged(page);
await page.click("[data-annotation-id='693R']", { count: 2 });
await awaitPromise(modeChangedHandle);
await page.waitForSelector("#highlightParamsToolbarContainer");
const editorSelector = getEditorSelector(6);
await page.waitForSelector(editorSelector);
await page.focus(editorSelector);
await waitForSelectedEditor(page, editorSelector);
await waitAndClick(
page,
`${editorSelector} .editToolbar button.colorPicker`
);
await waitAndClick(
page,
`${editorSelector} .editToolbar button[title = "Red"]`
);
await page.waitForSelector(
`.page[data-page-number = "1"] svg.highlight[fill = "#FF0102"]`
);
})
);
});
});
});

View file

@ -194,6 +194,11 @@ async function clearInput(page, selector, waitForInputEvent = false) {
: action();
}
async function waitAndClick(page, selector, clickOptions = {}) {
await page.waitForSelector(selector, { visible: true });
await page.click(selector, clickOptions);
}
function getSelector(id) {
return `[data-element-id="${id}"]`;
}
@ -800,6 +805,7 @@ export {
serializeBitmapDimensions,
setCaretAt,
switchToEditor,
waitAndClick,
waitForAnnotationEditorLayer,
waitForAnnotationModeChanged,
waitForEntryInStorage,

View file

@ -662,3 +662,5 @@
!file_pdfjs_test.pdf
!issue18536.pdf
!issue18561.pdf
!highlights.pdf
!highlight.pdf

BIN
test/pdfs/highlight.pdf Executable file

Binary file not shown.

BIN
test/pdfs/highlights.pdf Executable file

Binary file not shown.

View file

@ -10202,5 +10202,277 @@
"rounds": 1,
"link": true,
"type": "eq"
},
{
"id": "highlight-update-print",
"file": "pdfs/highlight.pdf",
"md5": "74671e2d9541931a606e886114bf3efa",
"rounds": 1,
"type": "eq",
"print": true,
"annotationStorage": {
"pdfjs_internal_editor_0": {
"annotationType": 9,
"color": [83, 255, 188],
"opacity": 1,
"thickness": 12,
"quadPoints": [
224.95899963378906, 649.6790161132812, 257.0950012207031,
649.6790161132812, 224.95899963378906, 665.8670043945312,
257.0950012207031, 665.8670043945312
],
"outlines": [
[
224.62632386, 649.4661241, 224.62632386, 666.0718055, 257.44364369,
666.0718055, 257.44364369, 649.4661241
]
],
"pageIndex": 0,
"rect": [224.62632386, 649.4661241, 257.44364369, 666.0718055],
"rotation": 0,
"structTreeParentId": null,
"id": "24R"
},
"pdfjs_internal_editor_1": {
"annotationType": 9,
"color": [128, 235, 255],
"opacity": 1,
"thickness": 12,
"quadPoints": null,
"outlines": {
"outline": [
null,
null,
null,
null,
231.02000427246094,
575.9500122070312,
234.9244860593802,
575.8426675799172,
235.67976763594078,
575.8027971554493,
236.50453905085675,
575.765994157359,
237.32931046577278,
575.7291911592689,
238.15139102232476,
575.6967454939373,
238.97078072051278,
575.6686571613642,
null,
null,
null,
null,
240.19986526779482,
575.6265246625046,
null,
null,
null,
null,
248.19520403340397,
575.3534715117306,
null,
null,
null,
null,
248.6047837595648,
587.3464796601443,
null,
null,
null,
null,
240.60944499395563,
587.6195328109183,
238.6632878655088,
587.6857348021831,
237.88825461323634,
587.7160188758909,
237.11665096007022,
587.7501062268005,
236.3450473069041,
587.7841935777101,
235.50103901924535,
587.8260330788092,
234.5846260970941,
587.875624730098,
null,
null,
null,
null,
231.02000427246094,
587.9500122070312
],
"points": [
[
231.02000427246094, 581.9500122070312, 241.21000671386722,
581.9500122070312, 243.60000610351562, 581.3499755859375, 246,
581.3499755859375, 248.39999389648438, 581.3499755859375,
248.39999389648438, 581.3499755859375
]
]
},
"pageIndex": 0,
"rect": [
230.69150427246095, 575.1494715117307, 248.9332837595648,
588.1540122070312
],
"rotation": 0,
"structTreeParentId": null,
"id": "41R"
}
}
},
{
"id": "highlight-update-save-print",
"file": "pdfs/highlight.pdf",
"md5": "74671e2d9541931a606e886114bf3efa",
"rounds": 1,
"type": "eq",
"save": true,
"print": true,
"annotationStorage": {
"pdfjs_internal_editor_0": {
"annotationType": 9,
"color": [83, 255, 188],
"opacity": 1,
"thickness": 12,
"quadPoints": [
224.95899963378906, 649.6790161132812, 257.0950012207031,
649.6790161132812, 224.95899963378906, 665.8670043945312,
257.0950012207031, 665.8670043945312
],
"outlines": [
[
224.62632386, 649.4661241, 224.62632386, 666.0718055, 257.44364369,
666.0718055, 257.44364369, 649.4661241
]
],
"pageIndex": 0,
"rect": [224.62632386, 649.4661241, 257.44364369, 666.0718055],
"rotation": 0,
"structTreeParentId": null,
"id": "24R"
},
"pdfjs_internal_editor_1": {
"annotationType": 9,
"color": [128, 235, 255],
"opacity": 1,
"thickness": 12,
"quadPoints": null,
"outlines": {
"outline": [
null,
null,
null,
null,
231.02000427246094,
575.9500122070312,
234.9244860593802,
575.8426675799172,
235.67976763594078,
575.8027971554493,
236.50453905085675,
575.765994157359,
237.32931046577278,
575.7291911592689,
238.15139102232476,
575.6967454939373,
238.97078072051278,
575.6686571613642,
null,
null,
null,
null,
240.19986526779482,
575.6265246625046,
null,
null,
null,
null,
248.19520403340397,
575.3534715117306,
null,
null,
null,
null,
248.6047837595648,
587.3464796601443,
null,
null,
null,
null,
240.60944499395563,
587.6195328109183,
238.6632878655088,
587.6857348021831,
237.88825461323634,
587.7160188758909,
237.11665096007022,
587.7501062268005,
236.3450473069041,
587.7841935777101,
235.50103901924535,
587.8260330788092,
234.5846260970941,
587.875624730098,
null,
null,
null,
null,
231.02000427246094,
587.9500122070312
],
"points": [
[
231.02000427246094, 581.9500122070312, 241.21000671386722,
581.9500122070312, 243.60000610351562, 581.3499755859375, 246,
581.3499755859375, 248.39999389648438, 581.3499755859375,
248.39999389648438, 581.3499755859375
]
]
},
"pageIndex": 0,
"rect": [
230.69150427246095, 575.1494715117307, 248.9332837595648,
588.1540122070312
],
"rotation": 0,
"structTreeParentId": null,
"id": "41R"
}
}
},
{
"id": "highlight-delete-print",
"file": "pdfs/highlight.pdf",
"md5": "74671e2d9541931a606e886114bf3efa",
"rounds": 1,
"type": "eq",
"print": true,
"annotationStorage": {
"pdfjs_internal_editor_0": {
"annotationType": 9,
"id": "24R",
"deleted": true,
"pageIndex": 0
}
}
},
{
"id": "highlight-delete-save-print",
"file": "pdfs/highlight.pdf",
"md5": "74671e2d9541931a606e886114bf3efa",
"rounds": 1,
"type": "eq",
"print": true,
"save": true,
"annotationStorage": {
"pdfjs_internal_editor_1": {
"annotationType": 9,
"id": "41R",
"deleted": true,
"pageIndex": 0
}
}
}
]