<commit_before>class KDAutoCompleteController extends KDViewController
  constructor:(options = {},data)->
    options = $.extend
      view                  : mainView = options.view or new KDAutoComplete
        name                : options.name
        label               : options.label or new KDLabelView
          title             : options.name
      itemClass             : KDAutoCompleteListItemView
      selectedItemClass     : KDAutoCompletedItem
      nothingFoundItemClass : KDAutoCompleteNothingFoundItem
      fetchingItemClass     : KDAutoCompleteFetchingItem
      listWrapperCssClass   : ''
      minSuggestionLength   : 2
      selectedItemsLimit    : null
      itemDataPath          : ''
      separator             : ','
      wrapper               : 'parent'
      submitValuesAsText   : no
      defaultValue          : []
    ,options

    super options, data

    mainView.registerListener
      KDEventTypes: 'focus'
      listener: @
      callback:(event)=>
        @updateDropdownContents()

    @selectedItemData    = []
    @hiddenInputs        = {}
    @selectedItemCounter = 0

  reset:->
    subViews = @itemWrapper.getSubViews().slice()
    for item in subViews
      @removeFromSubmitQueue item

  loadView:(mainView)->
    @createDropDown()
    @getAutoCompletedItemParent()
    @setDefaultValue()

    mainView.registerListener KDEventTypes : 'keyup', callback : __utils.throttle(@keyUpOnInputView,300), listener : @
    mainView.registerListener KDEventTypes : 'keydown', listener : @, callback : @keyDownOnInputView

  setDefaultValue:(defaultItems)->
    {defaultValue, itemDataPath} = @getOptions()
    defaultItems or= defaultValue
    for item in defaultItems
      @addItemToSubmitQueue @getView(), item

  keyDownOnInputView:(autoCompleteView,event)=>
    switch event.which
      when 13, 9 #enter, tab
        unless autoCompleteView.getValue() is ""
          @submitAutoComplete autoCompleteView.getValue()
        else
          return yes
      when 27 #escape
        @hideDropdown()
      when 38 #uparrow
        @dropdown.getListView().goUp()
      when 40 #downarrow
        @dropdown.getListView().goDown()
        @getView().$input().blur()<commit_msg> Check itemClass before trying to remove from submitQueue<commit_after>class KDAutoCompleteController extends KDViewController
  constructor:(options = {},data)->
    options = $.extend
      view                  : mainView = options.view or new KDAutoComplete
        name                : options.name
        label               : options.label or new KDLabelView
          title             : options.name
      itemClass             : KDAutoCompleteListItemView
      selectedItemClass     : KDAutoCompletedItem
      nothingFoundItemClass : KDAutoCompleteNothingFoundItem
      fetchingItemClass     : KDAutoCompleteFetchingItem
      listWrapperCssClass   : ''
      minSuggestionLength   : 2
      selectedItemsLimit    : null
      itemDataPath          : ''
      separator             : ','
      wrapper               : 'parent'
      submitValuesAsText   : no
      defaultValue          : []
    ,options

    super options, data

    mainView.registerListener
      KDEventTypes: 'focus'
      listener: @
      callback:(event)=>
        @updateDropdownContents()

    @selectedItemData    = []
    @hiddenInputs        = {}
    @selectedItemCounter = 0

  reset:->
    {itemClass} = @getOptions()
    subViews    = @itemWrapper.getSubViews().slice()
    for item in subViews
      if item instanceof itemClass
        @removeFromSubmitQueue item

  loadView:(mainView)->
    @createDropDown()
    @getAutoCompletedItemParent()
    @setDefaultValue()

    mainView.registerListener KDEventTypes : 'keyup', callback : __utils.throttle(@keyUpOnInputView,300), listener : @
    mainView.registerListener KDEventTypes : 'keydown', listener : @, callback : @keyDownOnInputView

  setDefaultValue:(defaultItems)->
    {defaultValue, itemDataPath} = @getOptions()
    defaultItems or= defaultValue
    for item in defaultItems
      @addItemToSubmitQueue @getView(), item

  keyDownOnInputView:(autoCompleteView,event)=>
    switch event.which
      when 13, 9 #enter, tab
        unless autoCompleteView.getValue() is ""
          @submitAutoComplete autoCompleteView.getValue()
        else
          return yes
      when 27 #escape
        @hideDropdown()
      when 38 #uparrow
        @dropdown.getListView().goUp()
      when 40 #downarrow
        @dropdown.getListView().goDown()
        @getView().$input().blur()
{'fraction_non_alphanumeric': 0.08487247141600704, 'fraction_numerical': 0.006156552330694811, 'mean_word_length': 2.402393418100224, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '2010161', 'n_tokens_mistral': 1247, 'n_tokens_neox': 1172, 'n_words': 263}