Use presenter state for placeholder text
Signed-off-by: Nathan Sobo <nathan@github.com>
Esse commit está contido em:
@@ -197,6 +197,18 @@ describe "TextEditorPresenter", ->
|
||||
expectStateUpdate presenter, -> editor.setMini(true)
|
||||
expect(presenter.state.content.backgroundColor).toBeNull()
|
||||
|
||||
describe ".placeholderText", ->
|
||||
it "is present when the editor has no text", ->
|
||||
editor.setPlaceholderText("the-placeholder-text")
|
||||
presenter = new TextEditorPresenter(model: editor)
|
||||
expect(presenter.state.content.placeholderText).toBeNull()
|
||||
|
||||
expectStateUpdate presenter, -> editor.setText("")
|
||||
expect(presenter.state.content.placeholderText).toBe "the-placeholder-text"
|
||||
|
||||
expectStateUpdate presenter, -> editor.setPlaceholderText("new-placeholder-text")
|
||||
expect(presenter.state.content.placeholderText).toBe "new-placeholder-text"
|
||||
|
||||
describe ".lines", ->
|
||||
lineStateForScreenRow = (presenter, screenRow) ->
|
||||
presenter.state.content.lines[presenter.model.tokenizedLineForScreenRow(screenRow).id]
|
||||
|
||||
@@ -20,12 +20,12 @@ LinesComponent = React.createClass
|
||||
{presenter} = @props
|
||||
|
||||
if presenter?
|
||||
{editor, presenter, placeholderText} = @props
|
||||
{editor, presenter} = @props
|
||||
|
||||
@oldState ?= {content: {lines: {}}}
|
||||
@newState = presenter.state
|
||||
{scrollHeight} = @newState
|
||||
{scrollWidth, backgroundColor} = @newState.content
|
||||
{scrollWidth, backgroundColor, placeholderText} = @newState.content
|
||||
|
||||
style =
|
||||
height: scrollHeight
|
||||
|
||||
@@ -58,7 +58,6 @@ TextEditorComponent = React.createClass
|
||||
if @performedInitialMeasurement
|
||||
[renderedStartRow, renderedEndRow] = @getRenderedRowRange()
|
||||
|
||||
placeholderText = editor.getPlaceholderText() if editor.isEmpty()
|
||||
visible = @isVisible()
|
||||
|
||||
{scrollHeight, scrollTop} = @presenter.state
|
||||
@@ -99,7 +98,7 @@ TextEditorComponent = React.createClass
|
||||
|
||||
LinesComponent {
|
||||
ref: 'lines', @presenter, editor, hostElement, @useHardwareAcceleration, useShadowDOM,
|
||||
mouseWheelScreenRow, visible, placeholderText, @backgroundColor
|
||||
mouseWheelScreenRow, visible, @backgroundColor
|
||||
}
|
||||
|
||||
ScrollbarComponent
|
||||
@@ -282,7 +281,6 @@ TextEditorComponent = React.createClass
|
||||
@subscribe editor.observeDecorations(@onDecorationAdded)
|
||||
@subscribe editor.onDidRemoveDecoration(@onDecorationRemoved)
|
||||
@subscribe editor.onDidChangeCharacterWidths(@onCharacterWidthsChanged)
|
||||
@subscribe editor.onDidChangePlaceholderText(@onPlaceholderTextChanged)
|
||||
@subscribe editor.$scrollTop.changes, @onScrollTopChanged
|
||||
@subscribe editor.$scrollLeft.changes, @onScrollLeftChanged
|
||||
@subscribe editor.$verticalScrollbarWidth.changes, @requestUpdate
|
||||
@@ -648,9 +646,6 @@ TextEditorComponent = React.createClass
|
||||
onCharacterWidthsChanged: (@scopedCharacterWidthsChangeCount) ->
|
||||
@requestUpdate()
|
||||
|
||||
onPlaceholderTextChanged: ->
|
||||
@requestUpdate()
|
||||
|
||||
handleDragUntilMouseUp: (event, dragHandler) ->
|
||||
{editor} = @props
|
||||
dragging = false
|
||||
|
||||
@@ -31,6 +31,7 @@ class TextEditorPresenter
|
||||
@disposables.add @model.onDidChange(@updateState.bind(this))
|
||||
@disposables.add @model.onDidChangeSoftWrapped(@updateState.bind(this))
|
||||
@disposables.add @model.onDidChangeGrammar(@updateContentState.bind(this))
|
||||
@disposables.add @model.onDidChangePlaceholderText(@updateContentState.bind(this))
|
||||
@disposables.add @model.onDidChangeMini =>
|
||||
@updateContentState()
|
||||
@updateLinesState()
|
||||
@@ -76,6 +77,7 @@ class TextEditorPresenter
|
||||
@state.content.scrollLeft = @getScrollLeft()
|
||||
@state.content.indentGuidesVisible = not @model.isMini() and atom.config.get('editor.showIndentGuide', scope: @model.getRootScopeDescriptor())
|
||||
@state.content.backgroundColor = if @model.isMini() then null else @getBackgroundColor()
|
||||
@state.content.placeholderText = if @model.isEmpty() then @model.getPlaceholderText() else null
|
||||
@emitter.emit 'did-update-state'
|
||||
|
||||
updateLinesState: ->
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário