<commit_before>var CoreView = require('backbone/core-view');
var _ = require('underscore');
var Ps = require('perfect-scrollbar');
var emptyTemplate = require('./custom-list-empty.tpl');
var addTemplate = require('./custom-list-add.tpl');
var template = require('./custom-list.tpl');
var ARROW_DOWN_KEY_CODE = 40;
var Utils = require('../../helpers/utils');
var ARROW_UP_KEY_CODE = 38;
var ENTER_KEY_CODE = 13;

module.exports = CoreView.extend({
  className: 'CDB-Text CDB-Size-medium CustomList-listWrapper',
  tagName: 'div',

  events: {
    'click .js-add-custom-value': '_onClickAddCustomValue'
  },

  initialize: function (opts) {
    this.options = _.extend({}, this.options, opts);
    this._onKeyDownBinded = this._onKeyDown.bind(this);
    this._initBinds();
  },

  render: function () {
    this.clearSubViews();
    this._removeArrowBinds();
    this._destroyCustomScroll();
    this.$el.empty();

    var query = this.model.get('query');
    var items = this.collection.search(query);

    this.$el.append(template());

    var allowFreeTextInput = this.options.allowFreeTextInput;
    var containsValue = !this.collection.containsValue(query);

    if (allowFreeTextInput && query && !Utils.isBlank(query) && containsValue) {
      this.$el.prepend(
        addTemplate({
          query: query,
          typeLabel: this.options.typeLabel
        })
      );
    }

    if (items.size() > 0) {
      items.each(this._renderItem, this);
      this._applyCustomScroll();
      this._applyArrowBinds();
    } else if (!allowFreeTextInput || Utils.isBlank(query)) {
      this.$el.append(
        emptyTemplate({
          query: query,
          typeLabel: this.options.typeLabel
        })
      );
    }

    return this;
  },

  _renderItem: function (mdl) {
    var ItemViewClass = this.options.ItemView;
    var itemView = new ItemViewClass({
      model: mdl,
      typeLabel: this.options.typeLabel,
      template: this.options.itemTemplate
    });
    this.$('.js-list').append(itemView.render().el);
    this.addView(itemView);
  },

  _initBinds: function () {
    this.model.bind('change:query', this.render, this);
  },

  _applyArrowBinds: function () {
    document.addEventListener('keydown', this._onKeyDownBinded);
  },

  _removeArrowBinds: function () {
    document.removeEventListener('keydown', this._onKeyDownBinded);
  },

  _getSelected: function () {
    var selectedModel = this.collection.getSelectedItem();
    var selectedValue;

    if (selectedModel) {
      selectedValue = selectedModel.getValue();
      return this.$('[data-val="' + selectedValue + '"]');
    }

    return null;<commit_msg>Fixed problem with data-val expression<commit_after>var CoreView = require('backbone/core-view');
var _ = require('underscore');
var Ps = require('perfect-scrollbar');
var emptyTemplate = require('./custom-list-empty.tpl');
var addTemplate = require('./custom-list-add.tpl');
var template = require('./custom-list.tpl');
var ARROW_DOWN_KEY_CODE = 40;
var Utils = require('../../helpers/utils');
var ARROW_UP_KEY_CODE = 38;
var ENTER_KEY_CODE = 13;

module.exports = CoreView.extend({
  className: 'CDB-Text CDB-Size-medium CustomList-listWrapper',
  tagName: 'div',

  events: {
    'click .js-add-custom-value': '_onClickAddCustomValue'
  },

  initialize: function (opts) {
    this.options = _.extend({}, this.options, opts);
    this._onKeyDownBinded = this._onKeyDown.bind(this);
    this._initBinds();
  },

  render: function () {
    this.clearSubViews();
    this._removeArrowBinds();
    this._destroyCustomScroll();
    this.$el.empty();

    var query = this.model.get('query');
    var items = this.collection.search(query);

    this.$el.append(template());

    var allowFreeTextInput = this.options.allowFreeTextInput;
    var containsValue = !this.collection.containsValue(query);

    if (allowFreeTextInput && query && !Utils.isBlank(query) && containsValue) {
      this.$el.prepend(
        addTemplate({
          query: query,
          typeLabel: this.options.typeLabel
        })
      );
    }

    if (items.size() > 0) {
      items.each(this._renderItem, this);
      this._applyCustomScroll();
      this._applyArrowBinds();
    } else if (!allowFreeTextInput || Utils.isBlank(query)) {
      this.$el.append(
        emptyTemplate({
          query: query,
          typeLabel: this.options.typeLabel
        })
      );
    }

    return this;
  },

  _renderItem: function (mdl) {
    var ItemViewClass = this.options.ItemView;
    var itemView = new ItemViewClass({
      model: mdl,
      typeLabel: this.options.typeLabel,
      template: this.options.itemTemplate
    });
    this.$('.js-list').append(itemView.render().el);
    this.addView(itemView);
  },

  _initBinds: function () {
    this.model.bind('change:query', this.render, this);
  },

  _applyArrowBinds: function () {
    document.addEventListener('keydown', this._onKeyDownBinded);
  },

  _removeArrowBinds: function () {
    document.removeEventListener('keydown', this._onKeyDownBinded);
  },

  _getSelected: function () {
    var selectedModel = this.collection.getSelectedItem();
    var selectedValue;

    if (selectedModel) {
      selectedValue = selectedModel.getValue();
      return this.$("[data-val='" + selectedValue + "']");
    }

    return null;
{'fraction_non_alphanumeric': 0.14893617021276595, 'fraction_numerical': 0.0026360384108454153, 'mean_word_length': 3.2091917591125196, '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': '4942251', 'n_tokens_mistral': 1674, 'n_tokens_neox': 1636, 'n_words': 297}