Skip to content

Commit 9c5d1bd

Browse files
committed
Add a slight delay when typing into the job log filter
Avoids applying the filter multiple times while typing, since that can be too slow and block the UI sometimes.
1 parent 00ed6c7 commit 9c5d1bd

1 file changed

Lines changed: 19 additions & 9 deletions

File tree

dashboard/assets/scripts/dashboard.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,6 @@ function regExpEscape(s) {
122122
return escaped;
123123
}
124124

125-
function addAnyChangeListener(elem, func) {
126-
// DOM0 handler for convenient use by Clear button
127-
elem.onchange = func;
128-
elem.addEventListener("keydown", func, false);
129-
elem.addEventListener("paste", func, false);
130-
elem.addEventListener("input", func, false);
131-
}
132-
133125
function scrollToBottom(elem) {
134126
// Scroll to the bottom. To avoid serious performance problems in Firefox,
135127
// use a big number instead of elem.scrollHeight.
@@ -284,7 +276,25 @@ class JobsRenderer {
284276
constructor(container, filterBox, historyLines, showNicks, contextMenuRenderer) {
285277
this.container = container;
286278
this.filterBox = filterBox;
287-
addAnyChangeListener(this.filterBox, () => this.applyFilter());
279+
this.filterTimeout = null;
280+
this.filterBox.onchange = (e) => {
281+
const repeats = [
282+
"insertText",
283+
"deleteContent",
284+
"deleteContentForward",
285+
"deleteContentBackward",
286+
];
287+
let ms = e && e.inputType && repeats.includes(e.inputType) ? 100 : 0;
288+
ms = !this.filterBox.value ? 0 : ms;
289+
clearTimeout(this.filterTimeout);
290+
this.filterTimeout = setTimeout(() => {
291+
if (this.filterBox.value !== this.filterBox.old) {
292+
this.applyFilter();
293+
this.filterBox.old = this.filterBox.value;
294+
}
295+
}, ms);
296+
};
297+
this.filterBox.oninput = this.filterBox.onchange;
288298
this.filterBox.onkeypress = (ev) => {
289299
// Don't let `j` or `k` in the filter box cause the job window to switch
290300
ev.stopPropagation();

0 commit comments

Comments
 (0)