Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support toggling the PDFFindBar options with the Enter key (issue 19175) #19185

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading