<commit_before>{CompositeDisposable, Disposable, Emitter} = require 'event-kit'
{Point, Range} = require 'text-buffer'
_ = require 'underscore-plus'
Decoration = require './decoration'

module.exports =
class TextEditorPresenter
  toggleCursorBlinkHandle: null
  startBlinkingCursorsAfterDelay: null
  stoppedScrollingTimeoutId: null
  mouseWheelScreenRow: null
  scopedCharacterWidthsChangeCount: 0
  overlayDimensions: {}
  minimumReflowInterval: 200

  constructor: (params) ->
    {@model, @autoHeight, @explicitHeight, @contentFrameWidth, @scrollTop, @scrollLeft, @boundingClientRect, @windowWidth, @windowHeight, @gutterWidth} = params
    {horizontalScrollbarHeight, verticalScrollbarWidth} = params
    {@lineHeight, @baseCharacterWidth, @backgroundColor, @gutterBackgroundColor, @tileSize} = params
    {@cursorBlinkPeriod, @cursorBlinkResumeDelay, @stoppedScrollingDelay, @focused} = params
    @measuredHorizontalScrollbarHeight = horizontalScrollbarHeight
    @measuredVerticalScrollbarWidth = verticalScrollbarWidth
    @gutterWidth ?= 0
    @tileSize ?= 6

    @disposables = new CompositeDisposable
    @emitter = new Emitter
    @visibleHighlights = {}
    @characterWidthsByScope = {}
    @rangesByDecorationId = {}
    @lineDecorationsByScreenRow = {}
    @lineNumberDecorationsByScreenRow = {}
    @customGutterDecorationsByGutterNameAndScreenRow = {}
    @transferMeasurementsToModel()
    @observeModel()
    @observeConfig()
    @buildState()
    @invalidateState()
    @startBlinkingCursors() if @focused
    @startReflowing() if @continuousReflow
    @updating = false

  setLinesYardstick: (@linesYardstick) ->

  destroy: ->
    @disposables.dispose()

  # Calls your `callback` when some changes in the model occurred and the current state has been updated.
  onDidUpdateState: (callback) ->
    @emitter.on 'did-update-state', callback

  emitDidUpdateState: ->
    @emitter.emit "did-update-state" if @isBatching()

  transferMeasurementsToModel: ->
    @model.setHeight(@explicitHeight) if @explicitHeight?
    @model.setWidth(@contentFrameWidth) if @contentFrameWidth?
    @model.setLineHeightInPixels(@lineHeight) if @lineHeight?
    @model.setDefaultCharWidth(@baseCharacterWidth) if @baseCharacterWidth?
    @model.setScrollTop(@scrollTop) if @scrollTop?
    @model.setScrollLeft(@scrollLeft) if @scrollLeft?
    @model.setVerticalScrollbarWidth(@measuredVerticalScrollbarWidth) if @measuredVerticalScrollbarWidth?
    @model.setHorizontalScrollbarHeight(@measuredHorizontalScrollbarHeight) if @measuredHorizontalScrollbarHeight?

  # Private: Determines whether {TextEditorPresenter} is currently batching changes.
  # Returns a {Boolean}, `true` if is collecting changes, `false` if is applying them.
  isBatching: ->
    @updating is false

  getStateForMeasurements: ->
    @updateVerticalDimensions()
    @updateScrollbarDimensions()
    @updateStartRow()
    @updateEndRow()

    @updateLineDecorations() if @shouldUpdateDecorations
    @updateTilesState() if @shouldUpdateLineNumbersState or @shouldUpdateLinesState

    @shouldUpdateLinesState = false
    @shouldUpdateLineNumbersState = false

    @state

  # Public: Gets this presenter's state, updating it just in time before returning from this function.
  # Returns a state {Object}, useful for rendering to screen.
  getState: ->
    @updating = true

    @linesYardstick.measure [@model.getLongestScreenRow()], =>
      @updateCommonGutterState()
      @updateHorizontalDimensions()
      @updateReflowState()

      @updateFocusedState() if @shouldUpdateFocusedState
      @updateHeightState() if @shouldUpdateHeightState
      @updateVerticalScrollState() if @shouldUpdateVerticalScrollState
      @updateHorizontalScrollState() if @shouldUpdateHorizontalScrollState
      @updateScrollbarsState() if @shouldUpdateScrollbarsState
      @updateHiddenInputState() if @shouldUpdateHiddenInputState
      @updateContentState() if @shouldUpdateContentState
      @updateHighlightDecorations() if @shouldUpdateDecorations
      @updateCursorsState() if @shouldUpdateCursorsState
      @updateOverlaysState() if @shouldUpdateOverlaysState
      @updateLineNumberGutterState() if @shouldUpdateLineNumberGutterState
      @updateGutterOrderState() if @shouldUpdateGutterOrderState
      @updateCustomGutterDecorationState() if @shouldUpdateCustomGutterDecorationState

    @updating = false<commit_msg>Reset only lines state<commit_after>{CompositeDisposable, Disposable, Emitter} = require 'event-kit'
{Point, Range} = require 'text-buffer'
_ = require 'underscore-plus'
Decoration = require './decoration'

module.exports =
class TextEditorPresenter
  toggleCursorBlinkHandle: null
  startBlinkingCursorsAfterDelay: null
  stoppedScrollingTimeoutId: null
  mouseWheelScreenRow: null
  scopedCharacterWidthsChangeCount: 0
  overlayDimensions: {}
  minimumReflowInterval: 200

  constructor: (params) ->
    {@model, @autoHeight, @explicitHeight, @contentFrameWidth, @scrollTop, @scrollLeft, @boundingClientRect, @windowWidth, @windowHeight, @gutterWidth} = params
    {horizontalScrollbarHeight, verticalScrollbarWidth} = params
    {@lineHeight, @baseCharacterWidth, @backgroundColor, @gutterBackgroundColor, @tileSize} = params
    {@cursorBlinkPeriod, @cursorBlinkResumeDelay, @stoppedScrollingDelay, @focused} = params
    @measuredHorizontalScrollbarHeight = horizontalScrollbarHeight
    @measuredVerticalScrollbarWidth = verticalScrollbarWidth
    @gutterWidth ?= 0
    @tileSize ?= 6

    @disposables = new CompositeDisposable
    @emitter = new Emitter
    @visibleHighlights = {}
    @characterWidthsByScope = {}
    @rangesByDecorationId = {}
    @lineDecorationsByScreenRow = {}
    @lineNumberDecorationsByScreenRow = {}
    @customGutterDecorationsByGutterNameAndScreenRow = {}
    @transferMeasurementsToModel()
    @observeModel()
    @observeConfig()
    @buildState()
    @invalidateState()
    @startBlinkingCursors() if @focused
    @startReflowing() if @continuousReflow
    @updating = false

  setLinesYardstick: (@linesYardstick) ->

  destroy: ->
    @disposables.dispose()

  # Calls your `callback` when some changes in the model occurred and the current state has been updated.
  onDidUpdateState: (callback) ->
    @emitter.on 'did-update-state', callback

  emitDidUpdateState: ->
    @emitter.emit "did-update-state" if @isBatching()

  transferMeasurementsToModel: ->
    @model.setHeight(@explicitHeight) if @explicitHeight?
    @model.setWidth(@contentFrameWidth) if @contentFrameWidth?
    @model.setLineHeightInPixels(@lineHeight) if @lineHeight?
    @model.setDefaultCharWidth(@baseCharacterWidth) if @baseCharacterWidth?
    @model.setScrollTop(@scrollTop) if @scrollTop?
    @model.setScrollLeft(@scrollLeft) if @scrollLeft?
    @model.setVerticalScrollbarWidth(@measuredVerticalScrollbarWidth) if @measuredVerticalScrollbarWidth?
    @model.setHorizontalScrollbarHeight(@measuredHorizontalScrollbarHeight) if @measuredHorizontalScrollbarHeight?

  # Private: Determines whether {TextEditorPresenter} is currently batching changes.
  # Returns a {Boolean}, `true` if is collecting changes, `false` if is applying them.
  isBatching: ->
    @updating is false

  getStateForMeasurements: ->
    @updateVerticalDimensions()
    @updateScrollbarDimensions()
    @updateStartRow()
    @updateEndRow()

    @updateLineDecorations() if @shouldUpdateDecorations
    @updateTilesState() if @shouldUpdateLinesState

    @shouldUpdateLinesState = false

    @state

  # Public: Gets this presenter's state, updating it just in time before returning from this function.
  # Returns a state {Object}, useful for rendering to screen.
  getState: ->
    @updating = true

    @linesYardstick.measure [@model.getLongestScreenRow()], =>
      @updateCommonGutterState()
      @updateHorizontalDimensions()
      @updateReflowState()

      @updateFocusedState() if @shouldUpdateFocusedState
      @updateHeightState() if @shouldUpdateHeightState
      @updateVerticalScrollState() if @shouldUpdateVerticalScrollState
      @updateHorizontalScrollState() if @shouldUpdateHorizontalScrollState
      @updateScrollbarsState() if @shouldUpdateScrollbarsState
      @updateHiddenInputState() if @shouldUpdateHiddenInputState
      @updateContentState() if @shouldUpdateContentState
      @updateHighlightDecorations() if @shouldUpdateDecorations
      @updateCursorsState() if @shouldUpdateCursorsState
      @updateOverlaysState() if @shouldUpdateOverlaysState
      @updateLineNumberGutterState() if @shouldUpdateLineNumberGutterState
      @updateGutterOrderState() if @shouldUpdateGutterOrderState
      @updateCustomGutterDecorationState() if @shouldUpdateCustomGutterDecorationState

    @updating = false
{'fraction_non_alphanumeric': 0.08929390187987161, 'fraction_numerical': 0.001375515818431912, 'mean_word_length': 5.308749096167752, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '4018999', 'n_tokens_mistral': 2513, 'n_tokens_neox': 2410, 'n_words': 522}