<commit_before>{_, $, ScrollView} = require 'atom'
ResultView = require './result-view'

module.exports =
class ResultsView extends ScrollView
  @content: ->
    @ol class: 'results-view list-tree focusable-panel', tabindex: -1

  initialize: ->
    super

    @pixelOverdraw = 100
    @lastRenderedResultIndex = 0

    @on 'core:move-down', =>
      @selectNextResult()

    @on 'core:move-up', =>
      @selectPreviousResult()

    @on 'scroll', =>
      @renderResults() if @shouldRenderMoreResults()

    @on 'core:confirm', =>
      @find('.selected').view?().confirm?()
      false

    @on 'mousedown', '.match-result, .path', (e) =>
      @find('.selected').removeClass('selected')
      view = $(e.srcElement).view()
      view.addClass('selected')
      view.confirm()

  setModel: (@model) ->
    @model.on 'result-added', @addResult
    @model.on 'result-removed', @removeResult

  beforeRemove: ->
    @clear()

  hasResults: ->
    @model.getResultCount() > 0

  addResult: (filePath, matches) =>
    resultView = @getResultView(filePath)

    if resultView
      resultView.renderMatches(matches)
    else
      @renderResults()
      @find('.search-result:first').addClass('selected') if @getPathCount() == 1

  removeResult: (filePath) =>
    resultView = @getResultView(filePath)
    resultView.renderMatches(null) if resultView

  renderResults: ({renderAll}={}) ->
    return unless @shouldRenderMoreResults()

    paths = @model.getPaths()
    for filePath in paths[@lastRenderedResultIndex..]
      result = @model.getResult(filePath)
      break if not renderAll and not @shouldRenderMoreResults()
      resultView = new ResultView(filePath, result)
      @append(resultView)
      @lastRenderedResultIndex++

    null # dont return an array
<commit_msg>Add a check for renderAll<commit_after>{_, $, ScrollView} = require 'atom'
ResultView = require './result-view'

module.exports =
class ResultsView extends ScrollView
  @content: ->
    @ol class: 'results-view list-tree focusable-panel', tabindex: -1

  initialize: ->
    super

    @pixelOverdraw = 100
    @lastRenderedResultIndex = 0

    @on 'core:move-down', =>
      @selectNextResult()

    @on 'core:move-up', =>
      @selectPreviousResult()

    @on 'scroll', =>
      @renderResults() if @shouldRenderMoreResults()

    @on 'core:confirm', =>
      @find('.selected').view?().confirm?()
      false

    @on 'mousedown', '.match-result, .path', (e) =>
      @find('.selected').removeClass('selected')
      view = $(e.srcElement).view()
      view.addClass('selected')
      view.confirm()

  setModel: (@model) ->
    @model.on 'result-added', @addResult
    @model.on 'result-removed', @removeResult

  beforeRemove: ->
    @clear()

  hasResults: ->
    @model.getResultCount() > 0

  addResult: (filePath, matches) =>
    resultView = @getResultView(filePath)

    if resultView
      resultView.renderMatches(matches)
    else
      @renderResults()
      @find('.search-result:first').addClass('selected') if @getPathCount() == 1

  removeResult: (filePath) =>
    resultView = @getResultView(filePath)
    resultView.renderMatches(null) if resultView

  renderResults: ({renderAll}={}) ->
    return unless renderAll or @shouldRenderMoreResults()

    paths = @model.getPaths()
    for filePath in paths[@lastRenderedResultIndex..]
      result = @model.getResult(filePath)
      break if not renderAll and not @shouldRenderMoreResults()
      resultView = new ResultView(filePath, result)
      @append(resultView)
      @lastRenderedResultIndex++

    null # dont return an array

{'fraction_non_alphanumeric': 0.14473316568873987, 'fraction_numerical': 0.003911707180776753, 'mean_word_length': 3.3393939393939394, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, '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': '1760933', 'n_tokens_mistral': 1117, 'n_tokens_neox': 1068, 'n_words': 238}