<commit_before>{Range, SelectListView} = require 'atom'

module.exports =
class CorrectionsView extends SelectListView
  initialize: (@editorView, @corrections, @misspellingRange) ->
    super
    @addClass('corrections popover-list')
    @attach()

  viewForItem: (word) ->
    element = document.createElement('li')
    element.textContent = word
    element

  selectNextItemView: ->
    super
    false

  selectPreviousItemView: ->
    super
    false

  confirmed: (correction) ->
    @cancel()
    return unless correction
    editor = @editorView.getEditor()
    editor.transact =>
      editor.setSelectedBufferRange(editor.bufferRangeForScreenRange(@misspellingRange))
      editor.insertText(correction)
    @editorView.focus()

  attach: ->
    @aboveCursor = false
    @setItems(@corrections)

    @editorView.appendToLinesView(this)
    @setPosition()
    @focusFilterEditor()

  getEmptyMessage: (itemCount) ->
    if itemCount is 0
      'No corrections'
    else
      super

  setPosition: ->
    { left, top } = @editorView.pixelPositionForScreenPosition(@misspellingRange.start)
    height = @outerHeight()
    potentialTop = top + @editorView.lineHeight
    potentialBottom = potentialTop - @editorView.scrollTop() + height

    if @aboveCursor or potentialBottom > @editorView.outerHeight()
      @aboveCursor = true
      @css(left: left, top: top - height, bottom: 'inherit')
    else
      @css(left: left, top: potentialTop, bottom: 'inherit')

  populateList: ->
    super

    @setPosition()<commit_msg>:lipstick: Remove spaces<commit_after>{Range, SelectListView} = require 'atom'

module.exports =
class CorrectionsView extends SelectListView
  initialize: (@editorView, @corrections, @misspellingRange) ->
    super
    @addClass('corrections popover-list')
    @attach()

  viewForItem: (word) ->
    element = document.createElement('li')
    element.textContent = word
    element

  selectNextItemView: ->
    super
    false

  selectPreviousItemView: ->
    super
    false

  confirmed: (correction) ->
    @cancel()
    return unless correction
    editor = @editorView.getEditor()
    editor.transact =>
      editor.setSelectedBufferRange(editor.bufferRangeForScreenRange(@misspellingRange))
      editor.insertText(correction)
    @editorView.focus()

  attach: ->
    @aboveCursor = false
    @setItems(@corrections)

    @editorView.appendToLinesView(this)
    @setPosition()
    @focusFilterEditor()

  getEmptyMessage: (itemCount) ->
    if itemCount is 0
      'No corrections'
    else
      super

  setPosition: ->
    {left, top} = @editorView.pixelPositionForScreenPosition(@misspellingRange.start)
    height = @outerHeight()
    potentialTop = top + @editorView.lineHeight
    potentialBottom = potentialTop - @editorView.scrollTop() + height

    if @aboveCursor or potentialBottom > @editorView.outerHeight()
      @aboveCursor = true
      @css(left: left, top: top - height, bottom: 'inherit')
    else
      @css(left: left, top: potentialTop, bottom: 'inherit')

  populateList: ->
    super

    @setPosition()
{'fraction_non_alphanumeric': 0.11006186909801367, 'fraction_numerical': 0.0006512536633018561, 'mean_word_length': 3.4846715328467153, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '6930674', 'n_tokens_mistral': 918, 'n_tokens_neox': 874, 'n_words': 193}