<commit_before>import Ember from 'ember';

export default Ember.Component.extend({
  /*-------------------------------
   | parameters and input/output  |
   -------------------------------*/
  classNames: 'completable-input',
  /**
   * Array: a list of possible completion for the input.
   */
  complements : [],
  /**
   * integer: how many character should be inputted before the completion panel shows up.
   */
  minForComplement: 3,

  /*-------------------
   | logic and setup  |
   -------------------*/
  /**
   * a filtered list of the complements that match the currently inputted characters
   */
  potentialComplements: [],
  /**
   * Handle the jQuery wiring mainly for the keyboard events on the input-text.
   */
  jqueryInitializer: function () {
    "use strict";
    var self = this;
    this.$('input.completable-input-entry').on('keyup', function (event) {
      if (event.keyCode === 40) {
        //key down:
        event.preventDefault(); event.stopPropagation();
        self.send('nextComplement');
      } else if (event.keyCode === 38) {
        //key up:
        event.preventDefault(); event.stopPropagation();
        self.send('previousComplement');
      }
    });
    this.$().focusin(function () {
      //using custom jQuery allow to manipulate the Event
      self.send('focusIn');
    }).focusout(function (e) {
      if (self.get('showCompletions')) {
        //then we should delay everything
        e.stopPropagation(); e.preventDefault();
        self.$('input.completable-input-entry').trigger(e);
      } else {
        self.send('focusOut');
      }
    });
  }.on('didInsertElement'),
  inputClassNames: function () {
    "use strict";
    return 'completable-input-entry ' + this.get('input-class');
  }.property('input-class'),
  inFocus: false,
  potentialComplementsRefresh: function () {
    "use strict";
    var self = this,
      value = this.get('value') || '',
      potentialComplements;
    Ember.run.once(function () {
      if (value.length >= self.get('minForComplement')) {
        potentialComplements = self.get('complements').map(function (item) {
          return Ember.Object.create({value: item, isActive: false});
        }).filter(function (item) {
          var prefix = item.value.slice(0, value.length);
          return prefix === value;
        }).sortBy('value');
        self.set('potentialComplements', potentialComplements);
      }
    });
  }.observes('complements.@each', 'minForComplement', 'value').on('init', 'focusIn'),
  activeComplement: null,
  isActiveUpdater: function () {
    "use strict";
    var activeComplement = this.get('activeComplement');
    this.get('potentialComplements').forEach(function (item) {
      item.set('isActive', item === activeComplement);
      if (item.get('isActive')) {
        Ember.Logger.debug('active item found!');
      }
    });
  }.observes('potentialComplements.@each', 'activeComplement').on('init'),
  activeComplementObs: function () {
    "use strict";<commit_msg>adding a caseSentitive option<commit_after>import Ember from 'ember';

export default Ember.Component.extend({
  /*-------------------------------
   | parameters and input/output  |
   -------------------------------*/
  classNames: 'completable-input',
  /**
   * Array: a list of possible completion for the input.
   */
  complements : [],
  /**
   * integer: how many character should be inputted before the completion panel shows up.
   */
  minForComplement: 3,
  /**
   * boolean: self-explanatory
   */
  caseSensitive: false,

  /*-------------------
   | logic and setup  |
   -------------------*/
  /**
   * a filtered list of the complements that match the currently inputted characters
   */
  potentialComplements: [],
  /**
   * Handle the jQuery wiring mainly for the keyboard events on the input-text.
   */
  jqueryInitializer: function () {
    "use strict";
    var self = this;
    this.$('input.completable-input-entry').on('keyup', function (event) {
      if (event.keyCode === 40) {
        //key down:
        event.preventDefault(); event.stopPropagation();
        self.send('nextComplement');
      } else if (event.keyCode === 38) {
        //key up:
        event.preventDefault(); event.stopPropagation();
        self.send('previousComplement');
      }
    });
    this.$().focusin(function () {
      //using custom jQuery allow to manipulate the Event
      self.send('focusIn');
    }).focusout(function (e) {
      if (self.get('showCompletions')) {
        //then we should delay everything
        e.stopPropagation(); e.preventDefault();
        self.$('input.completable-input-entry').trigger(e);
      } else {
        self.send('focusOut');
      }
    });
  }.on('didInsertElement'),
  inputClassNames: function () {
    "use strict";
    return 'completable-input-entry ' + this.get('input-class');
  }.property('input-class'),
  inFocus: false,
  potentialComplementsRefresh: function () {
    "use strict";
    var self = this,
      value = this.get('value') || '',
      potentialComplements;
    Ember.run.once(function () {
      if (value.length >= self.get('minForComplement')) {
        potentialComplements = self.get('complements').map(function (item) {
          return Ember.Object.create({value: item, isActive: false});
        }).filter(function (item) {
          var prefix = item.value.slice(0, value.length);
          if (this.get('caseSensitive')) {
            return prefix === value;
          } else {
            return prefix.toLowerCase() === value.toLowerCase();
          }
        }).sortBy('value');
        self.set('potentialComplements', potentialComplements);
      }
    });
  }.observes('complements.@each', 'minForComplement', 'value').on('init', 'focusIn'),
  activeComplement: null,
  isActiveUpdater: function () {
    "use strict";
    var activeComplement = this.get('activeComplement');
    this.get('potentialComplements').forEach(function (item) {
      item.set('isActive', item === activeComplement);
      if (item.get('isActive')) {
        Ember.Logger.debug('active item found!');
      }
    });
  }.observes('potentialComplements.@each', 'activeComplement').on('init'),
  activeComplementObs: function () {
    "use strict";
{'fraction_non_alphanumeric': 0.1814826700898588, 'fraction_numerical': 0.0019255455712451862, 'mean_word_length': 2.5174943566591423, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2540160', 'n_tokens_mistral': 1775, 'n_tokens_neox': 1750, 'n_words': 392}