diff --git a/web/pdf_find_bar.js b/web/pdf_find_bar.js index 44787f2505a9b..d76d4fe3dc43d 100644 --- a/web/pdf_find_bar.js +++ b/web/pdf_find_bar.js @@ -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() {