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

module.exports =
class SearchResultView extends View
  @content: (previewList, filePath, match) ->
    range = Range.fromObject(match.range)
    prefix = match.lineText[0...range.start.column]
    suffix = match.lineText[range.end.column..]

    @li class: 'search-result list-item', =>
      @span range.start.row + 1, class: 'line-number text-subtle'
      @span class: 'preview', =>
        @span prefix
        @span match.matchText, class: 'match highlight-info'
        @span suffix

  initialize: (@previewList, @filePath, @match) ->
    @subscribe @previewList, 'core:confirm', =>
      if @hasClass('selected')
        @highlightResult()
        false
    @on 'mousedown', (e) =>
      @highlightResult()
      @previewList.find('.selected').removeClass('selected')
      @addClass('selected')

  highlightResult: ->
    editSession = rootView.open(@filePath)
    editSession.setSelectedBufferRange(@match.range, autoscroll: true)
    @previewList.focus()

  scrollTo: -><commit_msg>Use the lineTextOffset in match results<commit_after>{View, Range} = require 'atom'

module.exports =
class SearchResultView extends View
  @content: (previewList, filePath, match) ->
    range = Range.fromObject(match.range)
    prefix = match.lineText[match.lineTextOffset...(match.lineTextOffset + range.start.column)]
    suffix = match.lineText[(match.lineTextOffset + range.end.column)..]

    @li class: 'search-result list-item', =>
      @span range.start.row + 1, class: 'line-number text-subtle'
      @span class: 'preview', =>
        @span prefix
        @span match.matchText, class: 'match highlight-info'
        @span suffix

  initialize: (@previewList, @filePath, @match) ->
    @subscribe @previewList, 'core:confirm', =>
      if @hasClass('selected')
        @highlightResult()
        false
    @on 'mousedown', (e) =>
      @highlightResult()
      @previewList.find('.selected').removeClass('selected')
      @addClass('selected')

  highlightResult: ->
    editSession = rootView.open(@filePath)
    editSession.setSelectedBufferRange(@match.range, autoscroll: true)
    @previewList.focus()

  scrollTo: ->
{'fraction_non_alphanumeric': 0.14496088357109987, 'fraction_numerical': 0.0013805798435342844, 'mean_word_length': 3.445807770961145, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '958893', 'n_tokens_mistral': 656, 'n_tokens_neox': 640, 'n_words': 139}