mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
Call it onDidUpdateState
This commit is contained in:
@@ -45,7 +45,7 @@ describe "TextEditorPresenter", ->
|
||||
|
||||
expectStateUpdate = (presenter, fn) ->
|
||||
updatedState = false
|
||||
disposable = presenter.onNeedsUpdate ->
|
||||
disposable = presenter.onDidUpdateState ->
|
||||
updatedState = true
|
||||
disposable.dispose()
|
||||
fn()
|
||||
@@ -586,7 +586,7 @@ describe "TextEditorPresenter", ->
|
||||
expect(presenter.getState().content.indentGuidesVisible).toBe false
|
||||
|
||||
stateUpdated = false
|
||||
presenter.onNeedsUpdate -> stateUpdated = true
|
||||
presenter.onDidUpdateState -> stateUpdated = true
|
||||
|
||||
waitsForPromise -> atom.packages.activatePackage('language-javascript')
|
||||
|
||||
@@ -2013,7 +2013,7 @@ describe "TextEditorPresenter", ->
|
||||
atom.config.set('editor.showLineNumbers', false, scopeSelector: '.source.js')
|
||||
expect(presenter.getState().gutter.visible).toBe true
|
||||
stateUpdated = false
|
||||
presenter.onNeedsUpdate -> stateUpdated = true
|
||||
presenter.onDidUpdateState -> stateUpdated = true
|
||||
|
||||
waitsForPromise -> atom.packages.activatePackage('language-javascript')
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ class TextEditorComponent
|
||||
cursorBlinkResumeDelay: @cursorBlinkResumeDelay
|
||||
stoppedScrollingDelay: 200
|
||||
|
||||
@presenter.onNeedsUpdate(@requestUpdate)
|
||||
@presenter.onDidUpdateState(@requestUpdate)
|
||||
|
||||
@domNode = document.createElement('div')
|
||||
if @useShadowDOM
|
||||
|
||||
@@ -31,12 +31,12 @@ class TextEditorPresenter
|
||||
destroy: ->
|
||||
@disposables.dispose()
|
||||
|
||||
# Calls your `callback` when some changes in the model occurred and the current state needs to be updated.
|
||||
onNeedsUpdate: (callback) ->
|
||||
@emitter.on 'needs-update', callback
|
||||
# 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
|
||||
|
||||
needsUpdate: ->
|
||||
@emitter.emit "needs-update" if @isBatching()
|
||||
emitDidUpdateState: ->
|
||||
@emitter.emit "did-update-state" if @isBatching()
|
||||
|
||||
transferMeasurementsToModel: ->
|
||||
@model.setHeight(@explicitHeight) if @explicitHeight?
|
||||
@@ -192,7 +192,7 @@ class TextEditorPresenter
|
||||
else
|
||||
@state.focused = @focused
|
||||
|
||||
@needsUpdate()
|
||||
@emitDidUpdateState()
|
||||
|
||||
updateHeightState: ->
|
||||
if @isBatching()
|
||||
@@ -203,7 +203,7 @@ class TextEditorPresenter
|
||||
else
|
||||
@state.height = null
|
||||
|
||||
@needsUpdate()
|
||||
@emitDidUpdateState()
|
||||
|
||||
updateVerticalScrollState: ->
|
||||
if @isBatching()
|
||||
@@ -217,7 +217,7 @@ class TextEditorPresenter
|
||||
@state.gutter.scrollTop = @scrollTop
|
||||
@state.verticalScrollbar.scrollTop = @scrollTop
|
||||
|
||||
@needsUpdate()
|
||||
@emitDidUpdateState()
|
||||
|
||||
updateHorizontalScrollState: ->
|
||||
if @isBatching()
|
||||
@@ -229,7 +229,7 @@ class TextEditorPresenter
|
||||
@state.content.scrollLeft = @scrollLeft
|
||||
@state.horizontalScrollbar.scrollLeft = @scrollLeft
|
||||
|
||||
@needsUpdate()
|
||||
@emitDidUpdateState()
|
||||
|
||||
updateScrollbarsState: ->
|
||||
if @isBatching()
|
||||
@@ -243,7 +243,7 @@ class TextEditorPresenter
|
||||
@state.verticalScrollbar.width = @measuredVerticalScrollbarWidth
|
||||
@state.verticalScrollbar.bottom = @horizontalScrollbarHeight
|
||||
|
||||
@needsUpdate()
|
||||
@emitDidUpdateState()
|
||||
|
||||
updateHiddenInputState: ->
|
||||
if @isBatching()
|
||||
@@ -265,7 +265,7 @@ class TextEditorPresenter
|
||||
@state.hiddenInput.height = height
|
||||
@state.hiddenInput.width = Math.max(width, 2)
|
||||
|
||||
@needsUpdate()
|
||||
@emitDidUpdateState()
|
||||
|
||||
updateContentState: ->
|
||||
if @isBatching()
|
||||
@@ -277,7 +277,7 @@ class TextEditorPresenter
|
||||
@state.content.backgroundColor = if @model.isMini() then null else @backgroundColor
|
||||
@state.content.placeholderText = if @model.isEmpty() then @model.getPlaceholderText() else null
|
||||
|
||||
@needsUpdate()
|
||||
@emitDidUpdateState()
|
||||
|
||||
updateLinesState: ->
|
||||
if @isBatching()
|
||||
@@ -307,7 +307,7 @@ class TextEditorPresenter
|
||||
unless visibleLineIds.hasOwnProperty(id)
|
||||
delete @state.content.lines[id]
|
||||
|
||||
@needsUpdate()
|
||||
@emitDidUpdateState()
|
||||
|
||||
updateLineState: (row, line) ->
|
||||
lineState = @state.content.lines[line.id]
|
||||
@@ -335,7 +335,7 @@ class TextEditorPresenter
|
||||
@state.content.cursors = {}
|
||||
@updateCursorState(cursor) for cursor in @model.cursors # using property directly to avoid allocation
|
||||
|
||||
@needsUpdate()
|
||||
@emitDidUpdateState()
|
||||
|
||||
updateCursorState: (cursor, destroyOnly = false) ->
|
||||
delete @state.content.cursors[cursor.id]
|
||||
@@ -348,7 +348,7 @@ class TextEditorPresenter
|
||||
pixelRect.width = @baseCharacterWidth if pixelRect.width is 0
|
||||
@state.content.cursors[cursor.id] = pixelRect
|
||||
|
||||
@needsUpdate()
|
||||
@emitDidUpdateState()
|
||||
|
||||
updateOverlaysState: ->
|
||||
if @isBatching()
|
||||
@@ -374,7 +374,7 @@ class TextEditorPresenter
|
||||
for id of @state.content.overlays
|
||||
delete @state.content.overlays[id] unless visibleDecorationIds[id]
|
||||
|
||||
@needsUpdate()
|
||||
@emitDidUpdateState()
|
||||
|
||||
updateGutterState: ->
|
||||
if @isBatching()
|
||||
@@ -387,7 +387,7 @@ class TextEditorPresenter
|
||||
else
|
||||
@backgroundColor
|
||||
|
||||
@needsUpdate()
|
||||
@emitDidUpdateState()
|
||||
|
||||
updateLineNumbersState: ->
|
||||
if @isBatching()
|
||||
@@ -435,7 +435,7 @@ class TextEditorPresenter
|
||||
for id of @state.gutter.lineNumbers
|
||||
delete @state.gutter.lineNumbers[id] unless visibleLineNumberIds[id]
|
||||
|
||||
@needsUpdate()
|
||||
@emitDidUpdateState()
|
||||
|
||||
updateStartRow: ->
|
||||
return unless @scrollTop? and @lineHeight?
|
||||
@@ -622,7 +622,7 @@ class TextEditorPresenter
|
||||
@stoppedScrollingTimeoutId = null
|
||||
@stoppedScrollingTimeoutId = setTimeout(@didStopScrolling.bind(this), @stoppedScrollingDelay)
|
||||
@state.content.scrollingVertically = true
|
||||
@needsUpdate()
|
||||
@emitDidUpdateState()
|
||||
|
||||
didStopScrolling: ->
|
||||
@state.content.scrollingVertically = false
|
||||
@@ -631,7 +631,7 @@ class TextEditorPresenter
|
||||
@updateLinesState()
|
||||
@updateLineNumbersState()
|
||||
else
|
||||
@needsUpdate()
|
||||
@emitDidUpdateState()
|
||||
|
||||
setScrollLeft: (scrollLeft) ->
|
||||
scrollLeft = @constrainScrollLeft(scrollLeft)
|
||||
@@ -895,7 +895,7 @@ class TextEditorPresenter
|
||||
decorationState.flashCount++
|
||||
decorationState.flashClass = flash.class
|
||||
decorationState.flashDuration = flash.duration
|
||||
@needsUpdate()
|
||||
@emitDidUpdateState()
|
||||
|
||||
didAddDecoration: (decoration) ->
|
||||
@observeDecoration(decoration)
|
||||
@@ -932,7 +932,7 @@ class TextEditorPresenter
|
||||
unless visibleHighlights[id]
|
||||
delete @state.content.highlights[id]
|
||||
|
||||
@needsUpdate()
|
||||
@emitDidUpdateState()
|
||||
|
||||
|
||||
removeFromLineDecorationCaches: (decoration, range) ->
|
||||
@@ -973,7 +973,7 @@ class TextEditorPresenter
|
||||
|
||||
if decoration.isDestroyed() or not marker.isValid() or range.isEmpty() or not range.intersectsRowRange(@startRow, @endRow - 1)
|
||||
delete @state.content.highlights[decoration.id]
|
||||
@needsUpdate()
|
||||
@emitDidUpdateState()
|
||||
return
|
||||
|
||||
if range.start.row < @startRow
|
||||
@@ -985,7 +985,7 @@ class TextEditorPresenter
|
||||
|
||||
if range.isEmpty()
|
||||
delete @state.content.highlights[decoration.id]
|
||||
@needsUpdate()
|
||||
@emitDidUpdateState()
|
||||
return
|
||||
|
||||
highlightState = @state.content.highlights[decoration.id] ?= {
|
||||
@@ -996,7 +996,7 @@ class TextEditorPresenter
|
||||
highlightState.class = properties.class
|
||||
highlightState.deprecatedRegionClass = properties.deprecatedRegionClass
|
||||
highlightState.regions = @buildHighlightRegions(range)
|
||||
@needsUpdate()
|
||||
@emitDidUpdateState()
|
||||
|
||||
true
|
||||
|
||||
@@ -1083,10 +1083,10 @@ class TextEditorPresenter
|
||||
|
||||
toggleCursorBlink: ->
|
||||
@state.content.cursorsVisible = not @state.content.cursorsVisible
|
||||
@needsUpdate()
|
||||
@emitDidUpdateState()
|
||||
|
||||
pauseCursorBlinking: ->
|
||||
@stopBlinkingCursors(true)
|
||||
@startBlinkingCursorsAfterDelay ?= _.debounce(@startBlinkingCursors, @getCursorBlinkResumeDelay())
|
||||
@startBlinkingCursorsAfterDelay()
|
||||
@needsUpdate()
|
||||
@emitDidUpdateState()
|
||||
|
||||
Reference in New Issue
Block a user