Track horizontal/vertical scrollbar height/width in presenter

This commit is contained in:
Nathan Sobo 2015-01-28 17:50:42 -07:00
parent 9de8ab949f
commit 1b5be9aef8
2 changed files with 33 additions and 0 deletions

View File

@ -77,6 +77,21 @@ describe "TextEditorPresenter", ->
expectStateUpdate presenter, -> advanceClock(100)
expect(presenter.state.scrollingVertically).toBe false
describe ".scrollbars", ->
describe ".horizontalHeight", ->
it "tracks the value of ::horizontalScrollbarHeight", ->
presenter = new TextEditorPresenter(model: editor, horizontalScrollbarHeight: 10)
expect(presenter.state.scrollbars.horizontalHeight).toBe 10
expectStateUpdate presenter, -> presenter.setHorizontalScrollbarHeight(20)
expect(presenter.state.scrollbars.horizontalHeight).toBe 20
describe ".verticalWidth", ->
it "is assigned based on ::verticalScrollbarWidth", ->
presenter = new TextEditorPresenter(model: editor, verticalScrollbarWidth: 10)
expect(presenter.state.scrollbars.verticalWidth).toBe 10
expectStateUpdate presenter, -> presenter.setVerticalScrollbarWidth(20)
expect(presenter.state.scrollbars.verticalWidth).toBe 20
describe ".content", ->
describe ".scrollWidth", ->
it "is initialized as the max of the clientWidth and the width of the longest line", ->

View File

@ -11,6 +11,7 @@ class TextEditorPresenter
constructor: (params) ->
{@model, @clientHeight, @clientWidth, @scrollTop, @scrollLeft} = params
{@horizontalScrollbarHeight, @verticalScrollbarWidth} = params
{@lineHeight, @baseCharacterWidth, @lineOverdrawMargin, @backgroundColor, @gutterBackgroundColor} = params
{@cursorBlinkPeriod, @cursorBlinkResumeDelay, @stoppedScrollingDelay} = params
@ -51,6 +52,7 @@ class TextEditorPresenter
buildState: ->
@state =
scrollingVertically: false
scrollbars: {}
content:
blinkCursorsOff: false
lines: {}
@ -62,6 +64,7 @@ class TextEditorPresenter
updateState: ->
@updateVerticalScrollState()
@updateScrollbarsState()
@updateContentState()
@updateLinesState()
@updateCursorsState()
@ -74,6 +77,11 @@ class TextEditorPresenter
@state.scrollHeight = @computeScrollHeight()
@state.scrollTop = @getScrollTop()
updateScrollbarsState: ->
@state.scrollbars.horizontalHeight = @getHorizontalScrollbarHeight()
@state.scrollbars.verticalWidth = @getVerticalScrollbarWidth()
@emitter.emit 'did-update-state'
updateContentState: ->
@state.content.scrollWidth = @computeScrollWidth()
@state.content.scrollLeft = @getScrollLeft()
@ -391,6 +399,16 @@ class TextEditorPresenter
getScrollLeft: -> @scrollLeft
setHorizontalScrollbarHeight: (@horizontalScrollbarHeight) ->
@updateScrollbarsState()
getHorizontalScrollbarHeight: -> @horizontalScrollbarHeight
setVerticalScrollbarWidth: (@verticalScrollbarWidth) ->
@updateScrollbarsState()
getVerticalScrollbarWidth: -> @verticalScrollbarWidth
setClientHeight: (@clientHeight) ->
@updateVerticalScrollState()
@updateLinesState()