Skip to content

Commit

Permalink
Merge pull request mozilla#19185 from Snuffleupagus/issue-19175
Browse files Browse the repository at this point in the history
Support toggling the `PDFFindBar` options with the `Enter` key (issue 19175)
  • Loading branch information
Snuffleupagus authored Dec 6, 2024
2 parents 23c42f8 + 49326f7 commit b870c5d
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions web/pdf_find_bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand All @@ -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() {
Expand Down

0 comments on commit b870c5d

Please sign in to comment.