[Editor] Highlight text on a selectionchange event which hasn't been triggered by the pointer or the keyboard (bug 1976597)
It's useful for users highlighting with NVDA. They've to enable native selection and then selection some text. In this case only a selectionchange is triggered once the selection is done.
This commit is contained in:
parent
e5922f2e72
commit
a81e99168a
@ -637,6 +637,8 @@ class AnnotationEditorUIManager {
|
||||
|
||||
#isEnabled = false;
|
||||
|
||||
#isPointerDown = false;
|
||||
|
||||
#isWaiting = false;
|
||||
|
||||
#keyboardManagerAC = null;
|
||||
@ -857,6 +859,20 @@ class AnnotationEditorUIManager {
|
||||
evt => this.updateParams(evt.type, evt.value),
|
||||
{ signal }
|
||||
);
|
||||
window.addEventListener(
|
||||
"pointerdown",
|
||||
() => {
|
||||
this.#isPointerDown = true;
|
||||
},
|
||||
{ capture: true, signal }
|
||||
);
|
||||
window.addEventListener(
|
||||
"pointerup",
|
||||
() => {
|
||||
this.#isPointerDown = false;
|
||||
},
|
||||
{ capture: true, signal }
|
||||
);
|
||||
this.#addSelectionListener();
|
||||
this.#addDragAndDropListeners();
|
||||
this.#addKeyboardManager();
|
||||
@ -1299,6 +1315,7 @@ class AnnotationEditorUIManager {
|
||||
: null;
|
||||
activeLayer?.toggleDrawing();
|
||||
|
||||
if (this.#isPointerDown) {
|
||||
const ac = new AbortController();
|
||||
const signal = this.combinedSignal(ac);
|
||||
|
||||
@ -1315,6 +1332,13 @@ class AnnotationEditorUIManager {
|
||||
};
|
||||
window.addEventListener("pointerup", pointerup, { signal });
|
||||
window.addEventListener("blur", pointerup, { signal });
|
||||
} else {
|
||||
// Here neither the shift key nor the pointer is down and we've
|
||||
// something in the selection: we can be in the case where the user is
|
||||
// using a screen reader (see bug 1976597).
|
||||
activeLayer?.toggleDrawing(true);
|
||||
this.#onSelectEnd("main_toolbar");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -2801,4 +2801,61 @@ describe("Highlight Editor", () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Highlight the selection but without a mouse or a keyboard", () => {
|
||||
let pages;
|
||||
|
||||
beforeEach(async () => {
|
||||
pages = await loadAndWait(
|
||||
"tracemonkey.pdf",
|
||||
".annotationEditorLayer",
|
||||
null,
|
||||
null,
|
||||
{ highlightEditorColors: "red=#AB0000" }
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await closePages(pages);
|
||||
});
|
||||
|
||||
it("must highlight with red color", async () => {
|
||||
await Promise.all(
|
||||
pages.map(async ([browserName, page]) => {
|
||||
await switchToHighlight(page);
|
||||
|
||||
await page.evaluate(() => {
|
||||
// Take the first span which contains "Trace-based Just-in-Time..."
|
||||
const root = document.querySelector(
|
||||
".page[data-page-number='1'] > .textLayer"
|
||||
);
|
||||
const iter = document.createNodeIterator(
|
||||
root,
|
||||
NodeFilter.SHOW_TEXT
|
||||
);
|
||||
const textnode = iter.nextNode();
|
||||
const selection = document.getSelection();
|
||||
const range = document.createRange();
|
||||
range.selectNodeContents(textnode);
|
||||
selection.removeAllRanges();
|
||||
selection.addRange(range);
|
||||
});
|
||||
|
||||
await page.waitForSelector(`${getEditorSelector(0)}`);
|
||||
await page.waitForSelector(
|
||||
`.page[data-page-number = "1"] svg.highlightOutline.selected`
|
||||
);
|
||||
|
||||
const usedColor = await page.evaluate(() => {
|
||||
const highlight = document.querySelector(
|
||||
`.page[data-page-number = "1"] .canvasWrapper > svg.highlight`
|
||||
);
|
||||
return highlight.getAttribute("fill");
|
||||
});
|
||||
|
||||
expect(usedColor).withContext(`In ${browserName}`).toEqual("#AB0000");
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user