Skip to content

Commit

Permalink
[Editor] Ensure that highlightSelection waits until we've fully upd…
Browse files Browse the repository at this point in the history
…ated the editing-mode (issue 19369)

With the changes in PR 18843 the `AnnotationEditorUIManager.prototype.updateMode` method is now asynchronous, which we need to take into account when using the `highlightSelection` functionality.
  • Loading branch information
Snuffleupagus committed Jan 23, 2025
1 parent 877f698 commit aba346e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 18 deletions.
15 changes: 11 additions & 4 deletions src/display/editor/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -1003,10 +1003,17 @@ class AnnotationEditorUIManager {

switchToMode(mode, callback) {
// Switching to a mode can be asynchronous.
this._eventBus.on("annotationeditormodechanged", callback, {
once: true,
signal: this._signal,
});
this._eventBus.on(
"annotationeditormodechanged",
async evt => {
await this.#updateModeCapability?.promise;
callback(evt);
},
{
once: true,
signal: this._signal,
}
);
this._eventBus.dispatch("showannotationeditorui", {
source: this,
mode,
Expand Down
38 changes: 24 additions & 14 deletions test/integration/highlight_editor_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1481,23 +1481,33 @@ describe("Highlight Editor", () => {
it("must check that clicking on the highlight floating button triggers an highlight", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
const rect = await getSpanRectFromText(page, 1, "Abstract");
const x = rect.x + rect.width / 2;
const y = rect.y + rect.height / 2;
await page.mouse.click(x, y, { count: 2, delay: 100 });
async function floatingHighlight(text, editorId) {
const rect = await getSpanRectFromText(page, 1, text);
const x = rect.x + rect.width / 2;
const y = rect.y + rect.height / 2;
await page.mouse.click(x, y, { count: 2, delay: 100 });

await page.waitForSelector(".textLayer .highlightButton");
await page.click(".textLayer .highlightButton");

await page.waitForSelector(getEditorSelector(editorId));
const usedColor = await page.evaluate(() => {
const highlight = document.querySelector(
`.page[data-page-number = "1"] .canvasWrapper > svg.highlight`
);
return highlight.getAttribute("fill");
});

await page.waitForSelector(".textLayer .highlightButton");
await page.click(".textLayer .highlightButton");
expect(usedColor)
.withContext(`In ${browserName}`)
.toEqual("#AB0000");
}

await page.waitForSelector(getEditorSelector(0));
const usedColor = await page.evaluate(() => {
const highlight = document.querySelector(
`.page[data-page-number = "1"] .canvasWrapper > svg.highlight`
);
return highlight.getAttribute("fill");
});
await floatingHighlight("Abstract", 0);

expect(usedColor).withContext(`In ${browserName}`).toEqual("#AB0000");
// Disable editing mode, and highlight another string (issue 19369).
await switchToHighlight(page, /* disable */ true);
await floatingHighlight("Introduction", 1);
})
);
});
Expand Down

0 comments on commit aba346e

Please sign in to comment.