<commit_before>{View, $$} = require 'space-pen'
$ = require 'jquery'
_ = require 'underscore'
Range = require 'range'

module.exports =
class Autocomplete extends View
  @content: ->
    @div id: 'autocomplete', =>
      @ol outlet: 'matchesList'

  editor: null
  currentBuffer: null
  wordList: null
  wordRegex: /\w+/g
  matches: null
  currentMatchIndex: null
  isAutocompleting: false

  initialize: (@editor) ->
    requireStylesheet 'autocomplete.css'
    @on 'autocomplete:toggle', => @toggle()
    @on 'move-up', => @previousMatch()
    @on 'move-down', => @nextMatch()
    @editor.on 'buffer-path-change', => @setCurrentBuffer(@editor.buffer)

    @setCurrentBuffer(@editor.buffer)

  setCurrentBuffer: (buffer) ->
    @currentBuffer.off '.autocomplete' if @currentBuffer
    @currentBuffer = buffer
    @buildWordList()

    @currentBuffer.on 'change.autocomplete', =>
      @buildWordList() unless @isAutocompleting

  toggle: ->
    if @parent()[0] then @remove() else @show()

  show: ->
    @buildMatchList()
    @selectMatch(0) if @matches.length > 0

    cursorScreenPosition = @editor.getCursorScreenPosition()
    {left, top} = @editor.pixelOffsetForScreenPosition(cursorScreenPosition)
    @css {left: left, top: top + @editor.lineHeight}
    $(document.body).append(this)

  previousMatch: ->
    previousIndex = @currentMatchIndex - 1
    previousIndex = @matches.length - 1 if previousIndex < 0
    @selectMatch(previousIndex)<commit_msg>non-working version of autocomplete focusing<commit_after>{View, $$} = require 'space-pen'
$ = require 'jquery'
_ = require 'underscore'
Range = require 'range'

module.exports =
class Autocomplete extends View
  @content: ->
    @div id: 'autocomplete', tabindex: -1, =>
      @ol outlet: 'matchesList'

  editor: null
  currentBuffer: null
  wordList: null
  wordRegex: /\w+/g
  matches: null
  currentMatchIndex: null
  isAutocompleting: false

  initialize: (@editor) ->
    requireStylesheet 'autocomplete.css'
    @editor.on 'autocomplete:toggle', => @toggle()
    @on 'move-up', => @previousMatch()
    @on 'move-down', => @nextMatch()
    @editor.on 'buffer-path-change', => @setCurrentBuffer(@editor.buffer)

    @setCurrentBuffer(@editor.buffer)

  setCurrentBuffer: (buffer) ->
    @currentBuffer.off '.autocomplete' if @currentBuffer
    @currentBuffer = buffer
    @buildWordList()

    @currentBuffer.on 'change.autocomplete', =>
      @buildWordList() unless @isAutocompleting

  toggle: ->
    if @parent()[0] then @remove() else @show()

  show: ->
    @buildMatchList()
    @selectMatch(0) if @matches.length > 0

    cursorScreenPosition = @editor.getCursorScreenPosition()
    {left, top} = @editor.pixelOffsetForScreenPosition(cursorScreenPosition)
    @css {left: left, top: top + @editor.lineHeight}
    $(document.body).append(this)
    @focus()

  previousMatch: ->
    previousIndex = @currentMatchIndex - 1
    previousIndex = @matches.length - 1 if previousIndex < 0
    @selectMatch(previousIndex)
{'fraction_non_alphanumeric': 0.13993973886842986, 'fraction_numerical': 0.004352192835621024, 'mean_word_length': 3.922570016474465, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '2856231', 'n_tokens_mistral': 956, 'n_tokens_neox': 909, 'n_words': 212}