<commit_before>{Point, Range} = require 'text-buffer'
{Model} = require 'theorist'
{Emitter} = require 'event-kit'
_ = require 'underscore-plus'
Grim = require 'grim'

# Extended: The `Cursor` class represents the little blinking line identifying
# where text can be inserted.
#
# Cursors belong to {Editor}s and have some metadata attached in the form
# of a {Marker}.
module.exports =
class Cursor extends Model
  screenPosition: null
  bufferPosition: null
  goalColumn: null
  visible: true
  needsAutoscroll: null

  # Instantiated by an {Editor}
  constructor: ({@editor, @marker, id}) ->
    @emitter = new Emitter

    @assignId(id)
    @updateVisibility()
    @marker.onDidChange (e) =>
      @updateVisibility()
      {oldHeadScreenPosition, newHeadScreenPosition} = e
      {oldHeadBufferPosition, newHeadBufferPosition} = e
      {textChanged} = e
      return if oldHeadScreenPosition.isEqual(newHeadScreenPosition)

      # Supports old editor view
      @needsAutoscroll ?= @isLastCursor() and !textChanged
      @autoscroll() if @editor.manageScrollPosition and @isLastCursor() and textChanged

      @goalColumn = null

      movedEvent =
        oldBufferPosition: oldHeadBufferPosition
        oldScreenPosition: oldHeadScreenPosition
        newBufferPosition: newHeadBufferPosition
        newScreenPosition: newHeadScreenPosition
        textChanged: textChanged
        cursor: this

      @emit 'moved', movedEvent
      @emitter.emit 'did-change-position'
      @editor.cursorMoved(movedEvent)
    @marker.onDidDestroy =>
      @destroyed = true
      @editor.removeCursor(this)
      @emit 'destroyed'
      @emitter.emit 'did-destroy'
      @emitter.dispose()
    @needsAutoscroll = true

  destroy: ->
    @marker.destroy()

  ###
  Section: Event Subscription
  ###

  # Public: Calls your `callback` when the cursor has been moved.
  #
  # * `callback` {Function}
  #   * `event` {Object}
  #     * `oldBufferPosition` {Point}
  #     * `oldScreenPosition` {Point}
  #     * `newBufferPosition` {Point}
  #     * `newScreenPosition` {Point}
  #     * `textChanged` {Boolean}
  #
  # Returns a {Disposable} on which `.dispose()` can be called to unsubscribe.
  onDidChangePosition: (callback) ->
    @emitter.on 'did-change-position', callback

  # Public: Calls your `callback` when the cursor is destroyed
  #
  # * `callback` {Function}
  #
  # Returns a {Disposable} on which `.dispose()` can be called to unsubscribe.
  onDidDestroy: (callback) ->
    @emitter.on 'did-destroy', callback

  # Public: Calls your `callback` when the cursor's visibility has changed
  #
  # * `callback` {Function}
  #   * `visibility` {Boolean}
  #
  # Returns a {Disposable} on which `.dispose()` can be called to unsubscribe.
  onDidChangeVisibility: (callback) ->
    @emitter.on 'did-change-visibility', callback

  on: (eventName) -><commit_msg>Update Cursor::onDidChangePosition doc string<commit_after>{Point, Range} = require 'text-buffer'
{Model} = require 'theorist'
{Emitter} = require 'event-kit'
_ = require 'underscore-plus'
Grim = require 'grim'

# Extended: The `Cursor` class represents the little blinking line identifying
# where text can be inserted.
#
# Cursors belong to {Editor}s and have some metadata attached in the form
# of a {Marker}.
module.exports =
class Cursor extends Model
  screenPosition: null
  bufferPosition: null
  goalColumn: null
  visible: true
  needsAutoscroll: null

  # Instantiated by an {Editor}
  constructor: ({@editor, @marker, id}) ->
    @emitter = new Emitter

    @assignId(id)
    @updateVisibility()
    @marker.onDidChange (e) =>
      @updateVisibility()
      {oldHeadScreenPosition, newHeadScreenPosition} = e
      {oldHeadBufferPosition, newHeadBufferPosition} = e
      {textChanged} = e
      return if oldHeadScreenPosition.isEqual(newHeadScreenPosition)

      # Supports old editor view
      @needsAutoscroll ?= @isLastCursor() and !textChanged
      @autoscroll() if @editor.manageScrollPosition and @isLastCursor() and textChanged

      @goalColumn = null

      movedEvent =
        oldBufferPosition: oldHeadBufferPosition
        oldScreenPosition: oldHeadScreenPosition
        newBufferPosition: newHeadBufferPosition
        newScreenPosition: newHeadScreenPosition
        textChanged: textChanged
        cursor: this

      @emit 'moved', movedEvent
      @emitter.emit 'did-change-position'
      @editor.cursorMoved(movedEvent)
    @marker.onDidDestroy =>
      @destroyed = true
      @editor.removeCursor(this)
      @emit 'destroyed'
      @emitter.emit 'did-destroy'
      @emitter.dispose()
    @needsAutoscroll = true

  destroy: ->
    @marker.destroy()

  ###
  Section: Event Subscription
  ###

  # Public: Calls your `callback` when the cursor has been moved.
  #
  # * `callback` {Function}
  #   * `event` {Object}
  #     * `oldBufferPosition` {Point}
  #     * `oldScreenPosition` {Point}
  #     * `newBufferPosition` {Point}
  #     * `newScreenPosition` {Point}
  #     * `textChanged` {Boolean}
  #     * `Cursor` {Cursor} that triggered the event
  #
  # Returns a {Disposable} on which `.dispose()` can be called to unsubscribe.
  onDidChangePosition: (callback) ->
    @emitter.on 'did-change-position', callback

  # Public: Calls your `callback` when the cursor is destroyed
  #
  # * `callback` {Function}
  #
  # Returns a {Disposable} on which `.dispose()` can be called to unsubscribe.
  onDidDestroy: (callback) ->
    @emitter.on 'did-destroy', callback

  # Public: Calls your `callback` when the cursor's visibility has changed
  #
  # * `callback` {Function}
  #   * `visibility` {Boolean}
  #
  # Returns a {Disposable} on which `.dispose()` can be called to unsubscribe.
  onDidChangeVisibility: (callback) ->
    @emitter.on 'did-change-visibility', callback

  on: (eventName) ->
{'fraction_non_alphanumeric': 0.11070998796630566, 'fraction_numerical': 0.0, 'mean_word_length': 3.4209726443768997, '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': '5478156', 'n_tokens_mistral': 1789, 'n_tokens_neox': 1720, 'n_words': 485}