mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 22:58: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.#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.
|
||||
this.toggleButton.addEventListener("click", () => {
|
||||
this.toggle();
|
||||
|
@ -55,11 +62,14 @@ class PDFFindBar {
|
|||
this.dispatchEvent("");
|
||||
});
|
||||
|
||||
this.bar.addEventListener("keydown", e => {
|
||||
switch (e.keyCode) {
|
||||
this.bar.addEventListener("keydown", ({ keyCode, shiftKey, target }) => {
|
||||
switch (keyCode) {
|
||||
case 13: // Enter
|
||||
if (e.target === this.findField) {
|
||||
this.dispatchEvent("again", e.shiftKey);
|
||||
if (target === this.findField) {
|
||||
this.dispatchEvent("again", shiftKey);
|
||||
} else if (checkedInputs.has(target)) {
|
||||
target.checked = !target.checked;
|
||||
this.dispatchEvent(/* evtName = */ checkedInputs.get(target));
|
||||
}
|
||||
break;
|
||||
case 27: // Escape
|
||||
|
@ -71,26 +81,15 @@ class PDFFindBar {
|
|||
this.findPreviousButton.addEventListener("click", () => {
|
||||
this.dispatchEvent("again", true);
|
||||
});
|
||||
|
||||
this.findNextButton.addEventListener("click", () => {
|
||||
this.dispatchEvent("again", false);
|
||||
});
|
||||
|
||||
this.highlightAll.addEventListener("click", () => {
|
||||
this.dispatchEvent("highlightallchange");
|
||||
});
|
||||
|
||||
this.caseSensitive.addEventListener("click", () => {
|
||||
this.dispatchEvent("casesensitivitychange");
|
||||
});
|
||||
|
||||
this.entireWord.addEventListener("click", () => {
|
||||
this.dispatchEvent("entirewordchange");
|
||||
});
|
||||
|
||||
this.matchDiacritics.addEventListener("click", () => {
|
||||
this.dispatchEvent("diacriticmatchingchange");
|
||||
});
|
||||
for (const [elem, evtName] of checkedInputs) {
|
||||
elem.addEventListener("click", () => {
|
||||
this.dispatchEvent(evtName);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
reset() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue