diff --git a/src/background/omnibox.handlers.js b/src/background/omnibox.handlers.js index 3189814..a03805b 100644 --- a/src/background/omnibox.handlers.js +++ b/src/background/omnibox.handlers.js @@ -1,4 +1,4 @@ -import debounce from 'lodash/debounce'; +import throttle from 'lodash/throttle'; import { isChrome } from '../browser'; import { SEARCH_DEBOUNCE, OPTION_STRINGS as OPTIONS } from '../constants'; @@ -22,8 +22,8 @@ const getTargetsFromSettings = (settings) => { return targets; }; -export const onTextChangedFactory = (client, settings, { debounceTime = SEARCH_DEBOUNCE } = {}) => - debounce(async (text, suggest) => { +export const onTextChangedFactory = (client, settings, { debounceTime = SEARCH_DEBOUNCE } = {}) => { + const throttledSearch = throttle(async (text, suggest) => { const targets = getTargetsFromSettings(settings); const searchForks = !!settings[OPTIONS.SEARCH_FORKED]; const userLogins = []; @@ -46,6 +46,13 @@ export const onTextChangedFactory = (client, settings, { debounceTime = SEARCH_D console.error(err); } }, debounceTime); + return (text, suggest) => { + if (text.length < 2) { + return; + } + throttledSearch(text, suggest); + }; +}; export const onInputEnteredFactory = browser => (text, disposition) => { const url = text.startsWith('https://') diff --git a/src/constants.js b/src/constants.js index 076dd45..979d230 100644 --- a/src/constants.js +++ b/src/constants.js @@ -2,7 +2,7 @@ export const GITHUB_API = 'https://api.github.com/graphql'; export const GITHUB_OAUTH_URL = 'https://github.com/login/oauth/authorize'; export const GITHUB_TOKEN_URL = 'https://github.com/login/oauth/access_token'; export const REDIRECT_URL = 'https://github.com/gmenih341/github-omnibox'; -export const SEARCH_DEBOUNCE = 50; +export const SEARCH_DEBOUNCE = 200; export const OPTION_STRINGS = { GITHUB_TOKEN: '__github.token', GITHUB_LOGINS: '__github.logins',