mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 06:38:07 +02:00
Support toggling the PDFFindBar
options with the Enter
key (issue 19175)
These DOM elements are `input type="checkbox"` and (natively) only support being toggled with the `Space` key, however we can extend an existing event-listener to "manually" support the `Enter` key as well.
This commit is contained in:
parent
60eba287d4
commit
49326f71c2
1 changed files with 19 additions and 20 deletions
|
@ -46,6 +46,13 @@ class PDFFindBar {
|
||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
this.#mainContainer = mainContainer;
|
this.#mainContainer = mainContainer;
|
||||||
|
|
||||||
|
const checkedInputs = new Map([
|
||||||
|
[this.highlightAll, "highlightallchange"],
|
||||||
|
[this.caseSensitive, "casesensitivitychange"],
|
||||||
|
[this.entireWord, "entirewordchange"],
|
||||||
|
[this.matchDiacritics, "diacriticmatchingchange"],
|
||||||
|
]);
|
||||||
|
|
||||||
// Add event listeners to the DOM elements.
|
// Add event listeners to the DOM elements.
|
||||||
this.toggleButton.addEventListener("click", () => {
|
this.toggleButton.addEventListener("click", () => {
|
||||||
this.toggle();
|
this.toggle();
|
||||||
|
@ -55,11 +62,14 @@ class PDFFindBar {
|
||||||
this.dispatchEvent("");
|
this.dispatchEvent("");
|
||||||
});
|
});
|
||||||
|
|
||||||
this.bar.addEventListener("keydown", e => {
|
this.bar.addEventListener("keydown", ({ keyCode, shiftKey, target }) => {
|
||||||
switch (e.keyCode) {
|
switch (keyCode) {
|
||||||
case 13: // Enter
|
case 13: // Enter
|
||||||
if (e.target === this.findField) {
|
if (target === this.findField) {
|
||||||
this.dispatchEvent("again", e.shiftKey);
|
this.dispatchEvent("again", shiftKey);
|
||||||
|
} else if (checkedInputs.has(target)) {
|
||||||
|
target.checked = !target.checked;
|
||||||
|
this.dispatchEvent(/* evtName = */ checkedInputs.get(target));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 27: // Escape
|
case 27: // Escape
|
||||||
|
@ -71,26 +81,15 @@ class PDFFindBar {
|
||||||
this.findPreviousButton.addEventListener("click", () => {
|
this.findPreviousButton.addEventListener("click", () => {
|
||||||
this.dispatchEvent("again", true);
|
this.dispatchEvent("again", true);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.findNextButton.addEventListener("click", () => {
|
this.findNextButton.addEventListener("click", () => {
|
||||||
this.dispatchEvent("again", false);
|
this.dispatchEvent("again", false);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.highlightAll.addEventListener("click", () => {
|
for (const [elem, evtName] of checkedInputs) {
|
||||||
this.dispatchEvent("highlightallchange");
|
elem.addEventListener("click", () => {
|
||||||
});
|
this.dispatchEvent(evtName);
|
||||||
|
});
|
||||||
this.caseSensitive.addEventListener("click", () => {
|
}
|
||||||
this.dispatchEvent("casesensitivitychange");
|
|
||||||
});
|
|
||||||
|
|
||||||
this.entireWord.addEventListener("click", () => {
|
|
||||||
this.dispatchEvent("entirewordchange");
|
|
||||||
});
|
|
||||||
|
|
||||||
this.matchDiacritics.addEventListener("click", () => {
|
|
||||||
this.dispatchEvent("diacriticmatchingchange");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
reset() {
|
reset() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue