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

Add debounce to HUD.search() method #4547

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
25 changes: 16 additions & 9 deletions content_scripts/hud.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const HUD = {
tween: null,
hudUI: null,
findMode: null,
searchTimeout: null,
abandon() {
if (this.hudUI) {
this.hudUI.hide(false);
Expand Down Expand Up @@ -86,16 +87,22 @@ const HUD = {
},

search(data) {
// NOTE(mrmr1993): On Firefox, window.find moves the window focus away from the HUD. We use
// postFindFocus to put it back, so the user can continue typing.
this.findMode.findInPlace(data.query, {
"postFindFocus": this.hudUI.iframeElement.contentWindow,
});
if (this.searchTimeout) {
clearTimeout(this.searchTimeout);
}

// Show the number of matches in the HUD UI.
const matchCount = FindMode.query.parsedQuery.length > 0 ? FindMode.query.matchCount : 0;
const showMatchText = FindMode.query.rawQuery.length > 0;
this.hudUI.postMessage({ name: "updateMatchesCount", matchCount, showMatchText });
this.searchTimeout = Utils.setTimeout(300, () => {
// NOTE(mrmr1993): On Firefox, window.find moves the window focus away from the HUD. We use
// postFindFocus to put it back, so the user can continue typing.
this.findMode.findInPlace(data.query, {
"postFindFocus": this.hudUI.iframeElement.contentWindow,
});

// Show the number of matches in the HUD UI.
const matchCount = FindMode.query.parsedQuery.length > 0 ? FindMode.query.matchCount : 0;
const showMatchText = FindMode.query.rawQuery.length > 0;
this.hudUI.postMessage({ name: "updateMatchesCount", matchCount, showMatchText });
});
},

// Hide the HUD.
Expand Down