<commit_before>import autoBind from 'auto-bind';
import m from 'mithril';
import SearchIconComponent from './search-icon';

// A generic autocomplete-based search field
class SearchFieldComponent {

  constructor(vnode) {
    this.searcher = vnode.attrs.searcher;
    autoBind(this);
  }

  // Handle keyboard shortcuts for navigating results
  handleKeyboardNav(keydownEvent) {

    let keyCode = keydownEvent.keyCode;
    // Do not proceed if no results are selected
    if (this.searcher.results.length === 0) {
      // Prevent Mithril from redrawing for irrelevant keydown events
      keydownEvent.redraw = false;
      return;
    }

    if (keyCode === 13) {
      // On enter key, action selected result (by default, view the reference)
      this.searcher.getSelectedResult().runDefaultAction();
      keydownEvent.preventDefault();
      keydownEvent.redraw = false;
    } else if (keyCode === 40) {
      // On down arrow, select next result
      this.searcher.selectNextResult();
      keydownEvent.preventDefault();
    } else if (keyCode === 38) {
      // On up arrow, select previous result
      this.searcher.selectPrevResult();
      keydownEvent.preventDefault();
    } else {
      keydownEvent.redraw = false;
    }

  }

  // Run the main search function as soon as the search field contents change
  triggerSearch(inputEvent) {
    this.searcher.search(inputEvent.target.value);
    inputEvent.redraw = false;
  }

  view(vnode) {
    return m('div.search-field-container', [
      m('input[type=text].search-field', {
        autofocus: vnode.attrs.autofocus,
        placeholder: vnode.attrs.placeholder,
        value: this.searcher.queryStr,
        onkeydown: this.handleKeyboardNav,
        oninput: this.triggerSearch
      }),
      m(SearchIconComponent)
    ]);
  }

}

export default SearchFieldComponent;<commit_msg>Use destructuring to reference vnode attrs<commit_after>import autoBind from 'auto-bind';
import m from 'mithril';
import SearchIconComponent from './search-icon';

// A generic autocomplete-based search field
class SearchFieldComponent {

  constructor({attrs}) {
    this.searcher = attrs.searcher;
    autoBind(this);
  }

  // Handle keyboard shortcuts for navigating results
  handleKeyboardNav(keydownEvent) {

    let keyCode = keydownEvent.keyCode;
    // Do not proceed if no results are selected
    if (this.searcher.results.length === 0) {
      // Prevent Mithril from redrawing for irrelevant keydown events
      keydownEvent.redraw = false;
      return;
    }

    if (keyCode === 13) {
      // On enter key, action selected result (by default, view the reference)
      this.searcher.getSelectedResult().runDefaultAction();
      keydownEvent.preventDefault();
      keydownEvent.redraw = false;
    } else if (keyCode === 40) {
      // On down arrow, select next result
      this.searcher.selectNextResult();
      keydownEvent.preventDefault();
    } else if (keyCode === 38) {
      // On up arrow, select previous result
      this.searcher.selectPrevResult();
      keydownEvent.preventDefault();
    } else {
      keydownEvent.redraw = false;
    }

  }

  // Run the main search function as soon as the search field contents change
  triggerSearch(inputEvent) {
    this.searcher.search(inputEvent.target.value);
    inputEvent.redraw = false;
  }

  view({attrs}) {
    return m('div.search-field-container', [
      m('input[type=text].search-field', {
        autofocus: attrs.autofocus,
        placeholder: attrs.placeholder,
        value: this.searcher.queryStr,
        onkeydown: this.handleKeyboardNav,
        oninput: this.triggerSearch
      }),
      m(SearchIconComponent)
    ]);
  }

}

export default SearchFieldComponent;
{'fraction_non_alphanumeric': 0.1050228310502283, 'fraction_numerical': 0.0037604082728982004, 'mean_word_length': 2.9743863393810033, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '93676', 'n_tokens_mistral': 1085, 'n_tokens_neox': 1075, 'n_words': 274}