<commit_before>import {
  searchInput,
  deleteButton,
} from './constants';
import {
  scrollIfNeeded,
  populateTabList,
  overrideFontStylesWithSansSerif,
  appendSearchInputPlaceholderText,
} from './utils/dom';
import {
  getOsShortcut,
} from './utils/browser';
import {
  keydownHandler,
  configureSearch,
  clearInput,
  handleTabClick,
} from './event-callbacks';

export function addEventListeners(store) {
  const updateSearchResults = configureSearch(store);
  const handleKeydown = keydownHandler(store);
  window.addEventListener('keydown', handleKeydown);
  deleteButton.addEventListener('click', clearInput);
  searchInput.addEventListener('change', updateSearchResults);
  searchInput.addEventListener('keyup', updateSearchResults);

  // Populate store with current search fn
  return Object.assign(
    {},
    store,
    { updateSearchResults },
  );
}

export function addTabListeners(getState) {
  return function doAddTabListeners(tabNode) {
    tabNode.addEventListener('click', handleTabClick(getState), true);
    tabNode.addEventListener('focus', scrollIfNeeded);
  };
}

export function doFinalSideEffects(store) {
  const { updateSearchResults } = store;
  const { useFallbackFont } = store.getState().general;

  // Give a shortcut hint
  updatePlaceholderTextWithShortcutHint();
  // Populate the initial tab list here.
  // TODO: Add option for showing last query on popup
  populateTabList(updateSearchResults())
    .then(() => setTimeout(() => searchInput.focus(), 150))
    .catch((err) => {
      throw new Error(`Can't update search input placeholder text! ${err}`);
    });

  if (useFallbackFont) {
    // Lazy for now: Just override the css styles specifying a font-family
    overrideFontStylesWithSansSerif();
  }

  return store;
}


function updatePlaceholderTextWithShortcutHint() {
  const hintText = shortcut => `(${shortcut} opens this)`;
  return getOsShortcut()
    .then(hintText)
    .then(appendSearchInputPlaceholderText);
}<commit_msg>Lower input focus timeout (#13)<commit_after>import {
  searchInput,
  deleteButton,
} from './constants';
import {
  scrollIfNeeded,
  populateTabList,
  overrideFontStylesWithSansSerif,
  appendSearchInputPlaceholderText,
} from './utils/dom';
import {
  getOsShortcut,
} from './utils/browser';
import {
  keydownHandler,
  configureSearch,
  clearInput,
  handleTabClick,
} from './event-callbacks';

export function addEventListeners(store) {
  const updateSearchResults = configureSearch(store);
  const handleKeydown = keydownHandler(store);
  window.addEventListener('keydown', handleKeydown);
  deleteButton.addEventListener('click', clearInput);
  searchInput.addEventListener('change', updateSearchResults);
  searchInput.addEventListener('keyup', updateSearchResults);

  // Populate store with current search fn
  return Object.assign(
    {},
    store,
    { updateSearchResults },
  );
}

export function addTabListeners(getState) {
  return function doAddTabListeners(tabNode) {
    tabNode.addEventListener('click', handleTabClick(getState), true);
    tabNode.addEventListener('focus', scrollIfNeeded);
  };
}

export function doFinalSideEffects(store) {
  const { updateSearchResults } = store;
  const { useFallbackFont } = store.getState().general;

  // Give a shortcut hint
  updatePlaceholderTextWithShortcutHint();
  // Populate the initial tab list here.
  // TODO: Add option for showing last query on popup
  populateTabList(updateSearchResults())
    .then(() => setTimeout(() => searchInput.focus(), 100))
    .catch((err) => {
      throw new Error(`Can't update search input placeholder text! ${err}`);
    });

  if (useFallbackFont) {
    // Lazy for now: Just override the css styles specifying a font-family
    overrideFontStylesWithSansSerif();
  }

  return store;
}


function updatePlaceholderTextWithShortcutHint() {
  const hintText = shortcut => `(${shortcut} opens this)`;
  return getOsShortcut()
    .then(hintText)
    .then(appendSearchInputPlaceholderText);
}
{'fraction_non_alphanumeric': 0.11469265367316342, 'fraction_numerical': 0.001999000499750125, 'mean_word_length': 4.776334776334776, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4806813', 'n_tokens_mistral': 1153, 'n_tokens_neox': 1138, 'n_words': 270}