Skip to content

Commit ba38e2c

Browse files
committed
Reliably handle keypress in search box
Fixes #1174
1 parent ab92c9e commit ba38e2c

1 file changed

Lines changed: 5 additions & 13 deletions

File tree

templates/default/fulldoc/html/js/full_list.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
let searchTimeout = null;
44
const searchCache = [];
55
let caseSensitiveMatch = false;
6-
const ignoreKeyCodeMin = 8;
7-
const ignoreKeyCodeMax = 46;
8-
const commandKey = 91;
96

107
function query(selector, root) {
118
return (root || document).querySelector(selector);
@@ -151,28 +148,23 @@
151148

152149
if (!input || !fullList) return;
153150

154-
input.addEventListener("keyup", (event) => {
155-
if (ignoredKeyPress(event)) return;
151+
function updateSearchResults() {
156152
if (input.value === "") {
157153
clearSearch();
158154
} else {
159155
performSearch(input.value);
160156
}
161-
});
157+
}
158+
159+
input.addEventListener("input", updateSearchResults);
160+
input.addEventListener("change", updateSearchResults);
162161

163162
fullList.insertAdjacentHTML(
164163
"afterend",
165164
"<div id='noresults' role='status' style='display: none'></div>",
166165
);
167166
}
168167

169-
function ignoredKeyPress(event) {
170-
return (
171-
(event.keyCode > ignoreKeyCodeMin && event.keyCode < ignoreKeyCodeMax) ||
172-
event.keyCode === commandKey
173-
);
174-
}
175-
176168
function clearSearch() {
177169
clearSearchTimeout();
178170
queryAll("#full_list .found").forEach((node) => {

0 commit comments

Comments
 (0)