<commit_before>{Point, Range} = require 'telepath'
{Emitter} = require 'emissary'
_ = require 'underscore-plus'

# Public: The `Cursor` class represents the little blinking line identifying
# where text can be inserted.
#
# Cursors belong to {EditSession}s and have some metadata attached in the form
# of a {StringMarker}.
module.exports =
class Cursor
  Emitter.includeInto(this)

  screenPosition: null
  bufferPosition: null
  goalColumn: null
  visible: true
  needsAutoscroll: null

  # Private: Instantiated by an {EditSession}
  constructor: ({@editSession, @marker}) ->
    @updateVisibility()
    @marker.on 'changed', (e) =>
      @updateVisibility()
      {oldHeadScreenPosition, newHeadScreenPosition} = e
      {oldHeadBufferPosition, newHeadBufferPosition} = e
      {textChanged} = e
      return if oldHeadScreenPosition.isEqual(newHeadScreenPosition)

      @needsAutoscroll ?= @isLastCursor() and !textChanged

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

      @emit 'moved', movedEvent
      @editSession.emit 'cursor-moved', movedEvent<commit_msg>Autoscroll even when text does not change<commit_after>{Point, Range} = require 'telepath'
{Emitter} = require 'emissary'
_ = require 'underscore-plus'

# Public: The `Cursor` class represents the little blinking line identifying
# where text can be inserted.
#
# Cursors belong to {EditSession}s and have some metadata attached in the form
# of a {StringMarker}.
module.exports =
class Cursor
  Emitter.includeInto(this)

  screenPosition: null
  bufferPosition: null
  goalColumn: null
  visible: true
  needsAutoscroll: null

  # Private: Instantiated by an {EditSession}
  constructor: ({@editSession, @marker}) ->
    @updateVisibility()
    @marker.on 'changed', (e) =>
      @updateVisibility()
      {oldHeadScreenPosition, newHeadScreenPosition} = e
      {oldHeadBufferPosition, newHeadBufferPosition} = e
      {textChanged} = e
      return if oldHeadScreenPosition.isEqual(newHeadScreenPosition)

      @needsAutoscroll ?= @isLastCursor()

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

      @emit 'moved', movedEvent
      @editSession.emit 'cursor-moved', movedEvent
{'fraction_non_alphanumeric': 0.08408290965975752, 'fraction_numerical': 0.0, 'mean_word_length': 4.085487077534792, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2438121', 'n_tokens_mistral': 713, 'n_tokens_neox': 698, 'n_words': 199}