<commit_before>_ = require 'underscore-plus'
{$} = require 'atom'
{Subscriber, Emitter} = require 'emissary'
MinimapFindResultsView = null

module.exports =
class MinimapFindAndReplaceBinding
  Subscriber.includeInto(this)
  Emitter.includeInto(this)

  active: false

  constructor: (@findAndReplacePackage, @minimapPackage) ->
    @minimap = require(@minimapPackage.path)
    @findAndReplace = require(@findAndReplacePackage.path)

    MinimapFindResultsView = require('./minimap-find-results-view')()

    $(document).on 'find-and-replace:show', @activate
    atom.workspaceView.on 'core:cancel core:close', @deactivate
    @subscribe @minimap, 'activated.minimap', @activate
    @subscribe @minimap, 'deactivated.minimap', @deactivate

  activate: =>
    return @deactivate() unless @findViewIsVisible() and @minimapIsActive()
    return if @active
    @active = true

    @findView = @findAndReplace.findView
    @findModel = @findView.findModel
    @findResultsView = new MinimapFindResultsView(@findModel)

    @subscribe @findModel, 'updated', @markersUpdated

    setImmediate =>
      @findModel.emit('updated', _.clone(@findModel.markers))

  deactivate: =>
    return unless @active
    @active = false

    @findResultsView.detach()
    @unsubscribe @findModel, 'updated'

  destroy: ->
    @deactivate()

    $(document).off 'find-and-replace:show'
    atom.workspaceView.off 'core:cancel core:close'
    @unsubscribe()

    @findAndReplacePackage = null
    @findAndReplace = null
    @minimapPackage = null
    @minimap = null

  findViewIsVisible: -> @findAndReplace.findView?.parent().length isnt 0

  minimapIsActive: -> @minimap.active

  markersUpdated: =>
    @findResultsView.detach()
    @findResultsView.attach()<commit_msg>Fixes bad visibility test on find view<commit_after>_ = require 'underscore-plus'
{$} = require 'atom'
{Subscriber, Emitter} = require 'emissary'
MinimapFindResultsView = null

module.exports =
class MinimapFindAndReplaceBinding
  Subscriber.includeInto(this)
  Emitter.includeInto(this)

  active: false

  constructor: (@findAndReplacePackage, @minimapPackage) ->
    @minimap = require(@minimapPackage.path)
    @findAndReplace = require(@findAndReplacePackage.path)

    MinimapFindResultsView = require('./minimap-find-results-view')()

    $(document).on 'find-and-replace:show', @activate
    atom.workspaceView.on 'core:cancel core:close', @deactivate
    @subscribe @minimap, 'activated.minimap', @activate
    @subscribe @minimap, 'deactivated.minimap', @deactivate

  activate: =>
    return @deactivate() unless @findViewIsVisible() and @minimapIsActive()
    return if @active
    @active = true

    @findView = @findAndReplace.findView
    @findModel = @findView.findModel
    @findResultsView = new MinimapFindResultsView(@findModel)

    @subscribe @findModel, 'updated', @markersUpdated

    setImmediate =>
      @findModel.emit('updated', _.clone(@findModel.markers))

  deactivate: =>
    return unless @active
    @active = false

    @findResultsView.detach()
    @unsubscribe @findModel, 'updated'

  destroy: ->
    @deactivate()

    $(document).off 'find-and-replace:show'
    atom.workspaceView.off 'core:cancel core:close'
    @unsubscribe()

    @findAndReplacePackage = null
    @findAndReplace = null
    @minimapPackage = null
    @minimap = null

  findViewIsVisible: ->
    @findAndReplace.findView? and @findAndReplace.findView.parent().length is 1

  minimapIsActive: -> @minimap.active

  markersUpdated: =>
    @findResultsView.detach()
    @findResultsView.attach()
{'fraction_non_alphanumeric': 0.12324141812042769, 'fraction_numerical': 0.0005627462014631402, 'mean_word_length': 4.337837837837838, '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': '1073727', 'n_tokens_mistral': 1146, 'n_tokens_neox': 1103, 'n_words': 213}