<commit_before>var Select = require('./../index');

Select.prototype._select = function(option, index) {
  this.model.set('value', option[this.key]);
  this.model.set('selected', option);
  this.model.set('selectedIndex', index);
  this._closeOptions();
};

Select.prototype._willSelect = function() {  
  this.model.set('selectOptionsVisible', true);
};

Select.prototype._adjustDropdown = function(index) {
  var ul = this.optionListDropdown;
  
  if (index > 2) {
    index = index - 2;
    ul.scrollTop = (index * 40);
  } else {
    ul.scrollTop = 0;
  }
};

Select.prototype._addCloseListener = function () {
  var self = this;
  var lastIndex = this.optionListDropdown.children.length - 1;
  this.model.set('focusedIndex', this.model.get('selectedIndex'));

  this.focusListener = function (e) {
    if (e.target !== self.outputField) self._closeOptions();
  };

  this.clickListener = function (e) {
    if (!self.optionListDropdown.contains(e.target)) self._closeOptions();
  };

  this.keyListener = function (e) {
    if (e.keyCode === 27) return self._closeOptions();

    if (e.keyCode === 13) {
      e.stopPropagation();
      var index = self.model.get('focusedIndex');
      var option = self.model.get('optionList.' + index);

      self._validate();
      return self._select(option, index);
    }

    if (e.keyCode === 37 || e.keyCode === 38 && 
        self.model.get('focusedIndex') > 0) return self._adjustDropdown(self.model.increment('focusedIndex', -1));

    if (e.keyCode === 39 || e.keyCode === 40 && <commit_msg>Fix bug with side arrows being able to go to indices out of list range<commit_after>var Select = require('./../index');

Select.prototype._select = function(option, index) {
  this.model.set('value', option[this.key]);
  this.model.set('selected', option);
  this.model.set('selectedIndex', index);
  this._closeOptions();
};

Select.prototype._willSelect = function() {  
  this.model.set('selectOptionsVisible', true);
};

Select.prototype._adjustDropdown = function(index) {
  var ul = this.optionListDropdown;
  
  if (index > 2) {
    index = index - 2;
    ul.scrollTop = (index * 40);
  } else {
    ul.scrollTop = 0;
  }
};

Select.prototype._addCloseListener = function () {
  var self = this;
  var lastIndex = this.optionListDropdown.children.length - 1;
  this.model.set('focusedIndex', this.model.get('selectedIndex'));

  this.focusListener = function (e) {
    if (e.target !== self.outputField) self._closeOptions();
  };

  this.clickListener = function (e) {
    if (!self.optionListDropdown.contains(e.target)) self._closeOptions();
  };

  this.keyListener = function (e) {
    if (e.keyCode === 27) return self._closeOptions();

    if (e.keyCode === 13) {
      e.stopPropagation();
      var index = self.model.get('focusedIndex');
      var option = self.model.get('optionList.' + index);

      self._validate();
      return self._select(option, index);
    }

    if ((e.keyCode === 37 || e.keyCode === 38) && 
        self.model.get('focusedIndex') > 0) return self._adjustDropdown(self.model.increment('focusedIndex', -1));

    if ((e.keyCode === 39 || e.keyCode === 40) && 
{'fraction_non_alphanumeric': 0.16968541468064824, 'fraction_numerical': 0.01271051795360661, 'mean_word_length': 3.4907275320970044, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '1522774', 'n_tokens_mistral': 1053, 'n_tokens_neox': 991, 'n_words': 206}