<commit_before>`import styleSupport from 'appkit/mixins/style-support'`
`import popupLayout from 'appkit/templates/components/eui-popup'`
`import itemViewClassTemplate from 'appkit/templates/components/eui-popup-option'`

popup = Em.Component.extend styleSupport,
  layout: popupLayout
  classNames: ['eui-popup']
  classNameBindings: ['isOpen::eui-closing']
  attributeBindings: ['tabindex']

  labelPath: 'label'
  options: null
  listHeight: '80'
  listRowHeight: '20'
  searchString: null

  selection: null # Option currently selected
  highlightedIndex: -1 # Option currently highlighted
  action: undefined # Controls what happens if option is clicked. Select it or perform Action

  previousFocus: null # Where the user's focus was before the popup was opened (only for keyboard nav)

  highlightedOption: (->
    options = @get('filteredOptions')
    index = @get('highlightedIndex')
    options[index]
  ).property 'highlightedIndex', 'filteredOptions'

  hide: ->
    @set('isOpen', false).set('highlightedIndex', -1)
    $(window).unbind('scroll.emberui')
    $(window).unbind('click.emberui')
    @get('previousFocus').focus()

    # Wait for any closing animation to finish before we remove it from the DOM
    # TODO: Remove from DOM event is no closing animation
    @$().one 'webkitAnimationEnd oanimationend msAnimationEnd animationend', =>
      @destroy()

  didInsertElement: ->
    @set('isOpen', true)
    @set('previousFocus', $("*:focus"))

    # Focus on search after popup is positioned or the page may scroll
    Ember.run.next this, -> @focusOnSearch()

  # Focus on search input when popup shows so we can catch key input
  focusOnSearch: ->
    @$().find('input:first').focus()

  # Set the selection back to the first option if the users changes the search query
  searchStringDidChange: (->
    @set('highlightedIndex', 0) if @get('searchString')
  ).observes 'searchString'

  # Filter the option list based on the query entered into the search box
  filteredOptions: (->
    options = @get('options')
    query = @get('searchString')

    return [] unless options
    return options unless query

    labelPath = @get('labelPath')

    escapedQuery = query.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&")
    regex = new RegExp(escapedQuery, 'i')

    filteredOptions = options.filter (item, index, self) ->
      return if item == null

      label = item.get?(labelPath) or item[labelPath]
      regex.test(label)

    return filteredOptions
  ).property 'options.@each', 'labelPath', 'searchString'

  hasNoOptions: Ember.computed.empty 'filteredOptions'

  # Updates the list-view's height based on the number of options
  optionsLengthDidChange: (->
    @updateListHeight()
  ).observes 'filteredOptions.length'

  updateListHeight: ->
    optionCount = @get('filteredOptions.length')
    rowHeight = @get('listRowHeight')

    if optionCount <= 12
      @set('listHeight', (optionCount * rowHeight))
    else
      @set('listHeight', (10 * rowHeight))


  # Keyboard controls

  KEY_MAP:
    27: 'escapePressed'
    13: 'enterPressed'
    38: 'upArrowPressed'
    40: 'downArrowPressed'

  keyDown: (event) ->
    keyMap = @get 'KEY_MAP'
    method = keyMap[event.which]
    @get(method)?.apply(this, arguments) if method

  escapePressed: (event) ->
    @hide()

  enterPressed: (event) ->
    event.preventDefault()
    event = @get('event')
    selection = @get('options')[@get('highlightedIndex')]

    if event == 'select'
      @set('selection', selection)

    else if event == 'action'
      action = selection.get('action')
      @get('targetObject').triggerAction({action})

    @hide()

  downArrowPressed: (event) ->
    event.preventDefault() # Don't let the page scroll down
    @adjustHighlight(1)

  upArrowPressed: (event) ->
    event.preventDefault() # Don't let the page scroll down
    @adjustHighlight(-1)


  adjustHighlight: (indexAdjustment) ->
    highlightedIndex = @get('highlightedIndex')
    options = @get('filteredOptions')<commit_msg>fix selection via enter key to select correct option<commit_after>`import styleSupport from 'appkit/mixins/style-support'`
`import popupLayout from 'appkit/templates/components/eui-popup'`
`import itemViewClassTemplate from 'appkit/templates/components/eui-popup-option'`

popup = Em.Component.extend styleSupport,
  layout: popupLayout
  classNames: ['eui-popup']
  classNameBindings: ['isOpen::eui-closing']
  attributeBindings: ['tabindex']

  labelPath: 'label'
  options: null
  listHeight: '80'
  listRowHeight: '20'
  searchString: null

  selection: null # Option currently selected
  highlightedIndex: -1 # Option currently highlighted
  action: undefined # Controls what happens if option is clicked. Select it or perform Action

  previousFocus: null # Where the user's focus was before the popup was opened (only for keyboard nav)

  highlightedOption: (->
    options = @get('filteredOptions')
    index = @get('highlightedIndex')
    options[index]
  ).property 'highlightedIndex', 'filteredOptions'

  hide: ->
    @set('isOpen', false).set('highlightedIndex', -1)
    $(window).unbind('scroll.emberui')
    $(window).unbind('click.emberui')
    @get('previousFocus').focus()

    # Wait for any closing animation to finish before we remove it from the DOM
    # TODO: Remove from DOM event is no closing animation
    @$().one 'webkitAnimationEnd oanimationend msAnimationEnd animationend', =>
      @destroy()

  didInsertElement: ->
    @set('isOpen', true)
    @set('previousFocus', $("*:focus"))

    # Focus on search after popup is positioned or the page may scroll
    Ember.run.next this, -> @focusOnSearch()

  # Focus on search input when popup shows so we can catch key input
  focusOnSearch: ->
    @$().find('input:first').focus()

  # Set the selection back to the first option if the users changes the search query
  searchStringDidChange: (->
    @set('highlightedIndex', 0) if @get('searchString')
  ).observes 'searchString'

  # Filter the option list based on the query entered into the search box
  filteredOptions: (->
    options = @get('options')
    query = @get('searchString')

    return [] unless options
    return options unless query

    labelPath = @get('labelPath')

    escapedQuery = query.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&")
    regex = new RegExp(escapedQuery, 'i')

    filteredOptions = options.filter (item, index, self) ->
      return if item == null

      label = item.get?(labelPath) or item[labelPath]
      regex.test(label)

    return filteredOptions
  ).property 'options.@each', 'labelPath', 'searchString'

  hasNoOptions: Ember.computed.empty 'filteredOptions'

  # Updates the list-view's height based on the number of options
  optionsLengthDidChange: (->
    @updateListHeight()
  ).observes 'filteredOptions.length'

  updateListHeight: ->
    optionCount = @get('filteredOptions.length')
    rowHeight = @get('listRowHeight')

    if optionCount <= 12
      @set('listHeight', (optionCount * rowHeight))
    else
      @set('listHeight', (10 * rowHeight))


  # Keyboard controls

  KEY_MAP:
    27: 'escapePressed'
    13: 'enterPressed'
    38: 'upArrowPressed'
    40: 'downArrowPressed'

  keyDown: (event) ->
    keyMap = @get 'KEY_MAP'
    method = keyMap[event.which]
    @get(method)?.apply(this, arguments) if method

  escapePressed: (event) ->
    @hide()

  enterPressed: (event) ->
    event.preventDefault()
    event = @get('event')

    if event == 'select'
      @set('selection', @get('highlightedOption'))

    else if event == 'action'
      action = @get('highlightedOption.action')
      @get('targetObject').triggerAction({action})

    @hide()

  downArrowPressed: (event) ->
    event.preventDefault() # Don't let the page scroll down
    @adjustHighlight(1)

  upArrowPressed: (event) ->
    event.preventDefault() # Don't let the page scroll down
    @adjustHighlight(-1)


  adjustHighlight: (indexAdjustment) ->
    highlightedIndex = @get('highlightedIndex')
    options = @get('filteredOptions')
{'fraction_non_alphanumeric': 0.13064636885450462, 'fraction_numerical': 0.005240828550037434, 'mean_word_length': 3.816706730769231, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 37, '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': '339149', 'n_tokens_mistral': 2463, 'n_tokens_neox': 2335, 'n_words': 667}