<commit_before>{Emitter, CompositeDisposable} = require 'event-kit'

module.exports =
class DisplayMarker
  constructor: (@layer, @bufferMarker) ->
    {@id} = @bufferMarker
    @hasChangeObservers = false
    @emitter = new Emitter
    @disposables = null
    @destroyed = false

  destroy: ->
    @bufferMarker.destroy()
    @destroyed = true
    @emitter.emit('did-destroy')

  onDidDestroy: (callback) ->
    @emitter.on('did-destroy', callback)

  isDestroyed: -> @destroyed

  getBufferRange: ->
    @bufferMarker.getRange()

  getScreenRange: ->
    @layer.translateBufferRange(@getBufferRange())

  setBufferRange: (bufferRange, options) ->
    @bufferMarker.setRange(bufferRange, options)

  setScreenRange: (screenRange, options) ->
    @setBufferRange(@layer.translateScreenRange(screenRange, options), options)

  getHeadBufferPosition: ->
    @bufferMarker.getHeadPosition()

  setHeadBufferPosition: (bufferPosition, properties) ->
    @bufferMarker.setHeadPosition(bufferPosition, properties)

  getHeadScreenPosition: ->
    @layer.translateBufferPosition(@bufferMarker.getHeadPosition())

  setHeadScreenPosition: (screenPosition, options) ->
    bufferPosition = @layer.translateScreenPosition(screenPosition, options)
    @bufferMarker.setHeadPosition(bufferPosition, options)

  getTailBufferPosition: ->
    @bufferMarker.getTailPosition()

  setTailBufferPosition: (bufferPosition, options) ->
    @bufferMarker.setTailPosition(bufferPosition, options)

  getTailScreenPosition: ->
    @layer.translateBufferPosition(@bufferMarker.getTailPosition())

  setTailScreenPosition: (screenPosition, options) ->
    bufferPosition = @layer.translateScreenPosition(screenPosition, options)
    @bufferMarker.setTailPosition(bufferPosition, options)

  isValid: ->
    @bufferMarker.isValid()

  isReversed: ->
    @bufferMarker.isReversed()

  getProperties: ->
    @bufferMarker.getProperties()

  setProperties: (properties) ->
    @bufferMarker.setProperties(properties)

  hasTail: ->
    @bufferMarker.hasTail()

  plantTail: ->
    @bufferMarker.plantTail()

  clearTail: ->
    @bufferMarker.clearTail()

  onDidChange: (callback) ->
    unless @hasChangeObservers
      @emitter = new Emitter
      @disposables = new CompositeDisposable
      @oldHeadBufferPosition = @getHeadBufferPosition()
      @oldHeadScreenPosition = @getHeadScreenPosition()
      @oldTailBufferPosition = @getTailBufferPosition()
      @oldTailScreenPosition = @getTailScreenPosition()
      @wasValid = @isValid()
      @disposables.add @bufferMarker.onDidChange (event) => @notifyObservers(event.textChanged)
      @hasChangeObservers = true
    @emitter.on 'did-change', callback

  notifyObservers: (textChanged) ->
    textChanged ?= false

    newHeadBufferPosition = @getHeadBufferPosition()
    newHeadScreenPosition = @getHeadScreenPosition()
    newTailBufferPosition = @getTailBufferPosition()
    newTailScreenPosition = @getTailScreenPosition()
    isValid = @isValid()

    return if isValid is @wasValid and
      newHeadBufferPosition.isEqual(@oldHeadBufferPosition) and
      newHeadScreenPosition.isEqual(@oldHeadScreenPosition) and
      newTailBufferPosition.isEqual(@oldTailBufferPosition) and
      newTailScreenPosition.isEqual(@oldTailScreenPosition)

    changeEvent = {
      @oldHeadScreenPosition, newHeadScreenPosition,
      @oldTailScreenPosition, newTailScreenPosition,
      @oldHeadBufferPosition, newHeadBufferPosition,
      @oldTailBufferPosition, newTailBufferPosition,
      textChanged,
      @wasValid,
      isValid
    }

    @oldHeadBufferPosition = newHeadBufferPosition
    @oldHeadScreenPosition = newHeadScreenPosition
    @oldTailBufferPosition = newTailBufferPosition
    @oldTailScreenPosition = newTailScreenPosition
    @wasValid = isValid

    @emitter.emit 'did-change', changeEvent
<commit_msg>Add missing APIs to DisplayMarker<commit_after>{Emitter, CompositeDisposable} = require 'event-kit'

module.exports =
class DisplayMarker
  constructor: (@layer, @bufferMarker) ->
    {@id} = @bufferMarker
    @hasChangeObservers = false
    @emitter = new Emitter
    @disposables = null
    @destroyed = false

  destroy: ->
    @bufferMarker.destroy()
    @destroyed = true
    @emitter.emit('did-destroy')

  compare: (otherMarker) ->
    @bufferMarker.compare(otherMarker.bufferMarker)

  onDidDestroy: (callback) ->
    @emitter.on('did-destroy', callback)

  isDestroyed: -> @destroyed

  getBufferRange: ->
    @bufferMarker.getRange()

  getScreenRange: ->
    @layer.translateBufferRange(@getBufferRange())

  setBufferRange: (bufferRange, options) ->
    @bufferMarker.setRange(bufferRange, options)

  setScreenRange: (screenRange, options) ->
    @setBufferRange(@layer.translateScreenRange(screenRange, options), options)

  getHeadBufferPosition: ->
    @bufferMarker.getHeadPosition()

  setHeadBufferPosition: (bufferPosition, properties) ->
    @bufferMarker.setHeadPosition(bufferPosition, properties)

  getHeadScreenPosition: ->
    @layer.translateBufferPosition(@bufferMarker.getHeadPosition())

  setHeadScreenPosition: (screenPosition, options) ->
    bufferPosition = @layer.translateScreenPosition(screenPosition, options)
    @bufferMarker.setHeadPosition(bufferPosition, options)

  getTailBufferPosition: ->
    @bufferMarker.getTailPosition()

  setTailBufferPosition: (bufferPosition, options) ->
    @bufferMarker.setTailPosition(bufferPosition, options)

  getTailScreenPosition: ->
    @layer.translateBufferPosition(@bufferMarker.getTailPosition())

  setTailScreenPosition: (screenPosition, options) ->
    bufferPosition = @layer.translateScreenPosition(screenPosition, options)
    @bufferMarker.setTailPosition(bufferPosition, options)

  getStartBufferPosition: ->
    @bufferMarker.getStartPosition()

  getEndBufferPosition: ->
    @bufferMarker.getEndPosition()

  isValid: ->
    @bufferMarker.isValid()

  isReversed: ->
    @bufferMarker.isReversed()

  getProperties: ->
    @bufferMarker.getProperties()

  setProperties: (properties) ->
    @bufferMarker.setProperties(properties)

  hasTail: ->
    @bufferMarker.hasTail()

  plantTail: ->
    @bufferMarker.plantTail()

  clearTail: ->
    @bufferMarker.clearTail()

  onDidChange: (callback) ->
    unless @hasChangeObservers
      @emitter = new Emitter
      @disposables = new CompositeDisposable
      @oldHeadBufferPosition = @getHeadBufferPosition()
      @oldHeadScreenPosition = @getHeadScreenPosition()
      @oldTailBufferPosition = @getTailBufferPosition()
      @oldTailScreenPosition = @getTailScreenPosition()
      @wasValid = @isValid()
      @disposables.add @bufferMarker.onDidChange (event) => @notifyObservers(event.textChanged)
      @hasChangeObservers = true
    @emitter.on 'did-change', callback

  notifyObservers: (textChanged) ->
    textChanged ?= false

    newHeadBufferPosition = @getHeadBufferPosition()
    newHeadScreenPosition = @getHeadScreenPosition()
    newTailBufferPosition = @getTailBufferPosition()
    newTailScreenPosition = @getTailScreenPosition()
    isValid = @isValid()

    return if isValid is @wasValid and
      newHeadBufferPosition.isEqual(@oldHeadBufferPosition) and
      newHeadScreenPosition.isEqual(@oldHeadScreenPosition) and
      newTailBufferPosition.isEqual(@oldTailBufferPosition) and
      newTailScreenPosition.isEqual(@oldTailScreenPosition)

    changeEvent = {
      @oldHeadScreenPosition, newHeadScreenPosition,
      @oldTailScreenPosition, newTailScreenPosition,
      @oldHeadBufferPosition, newHeadBufferPosition,
      @oldTailBufferPosition, newTailBufferPosition,
      textChanged,
      @wasValid,
      isValid
    }

    @oldHeadBufferPosition = newHeadBufferPosition
    @oldHeadScreenPosition = newHeadScreenPosition
    @oldTailBufferPosition = newTailBufferPosition
    @oldTailScreenPosition = newTailScreenPosition
    @wasValid = isValid

    @emitter.emit 'did-change', changeEvent

{'fraction_non_alphanumeric': 0.10016399646776838, 'fraction_numerical': 0.0, 'mean_word_length': 4.579169598874032, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 58, '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': '2068683', 'n_tokens_mistral': 2301, 'n_tokens_neox': 2234, 'n_words': 365}