Add .right and .bottom to presenter scrollbar states

This commit is contained in:
Nathan Sobo
2015-01-28 18:54:50 -07:00
parent 14776e3f0a
commit 0910e86357
2 changed files with 42 additions and 7 deletions

View File

@@ -111,6 +111,22 @@ describe "TextEditorPresenter", ->
expectStateUpdate presenter, -> presenter.setHorizontalScrollbarHeight(20)
expect(presenter.state.horizontalScrollbar.height).toBe 20
describe ".right", ->
it "is ::verticalScrollbarWidth if the vertical scrollbar is visible and 0 otherwise", ->
presenter = new TextEditorPresenter
model: editor
height: editor.getLineCount() * 10 + 50
contentFrameWidth: editor.getMaxScreenLineLength() * 10
baseCharacterWidth: 10
lineHeight: 10
horizontalScrollbarHeight: 10
verticalScrollbarWidth: 10
{state} = presenter
expect(state.horizontalScrollbar.right).toBe 0
presenter.setHeight((editor.getLineCount() * 10) - 1)
expect(state.horizontalScrollbar.right).toBe 10
describe ".verticalScrollbar", ->
describe ".visible", ->
it "is true if the scrollHeight exceeds the computed client height", ->
@@ -145,6 +161,22 @@ describe "TextEditorPresenter", ->
expectStateUpdate presenter, -> presenter.setVerticalScrollbarWidth(20)
expect(presenter.state.verticalScrollbar.width).toBe 20
describe ".bottom", ->
it "is ::horizontalScrollbarHeight if the horizontal scrollbar is visible and 0 otherwise", ->
presenter = new TextEditorPresenter
model: editor
height: editor.getLineCount() * 10 - 1
contentFrameWidth: editor.getMaxScreenLineLength() * 10 + 50
baseCharacterWidth: 10
lineHeight: 10
horizontalScrollbarHeight: 10
verticalScrollbarWidth: 10
{state} = presenter
expect(state.verticalScrollbar.bottom).toBe 0
presenter.setContentFrameWidth(editor.getMaxScreenLineLength() * 10)
expect(state.verticalScrollbar.bottom).toBe 10
describe ".content", ->
describe ".scrollWidth", ->
it "is initialized as the max of the ::contentFrameWidth and the width of the longest line", ->

View File

@@ -79,24 +79,27 @@ class TextEditorPresenter
@state.scrollTop = @getScrollTop()
updateScrollbarsState: ->
@state.horizontalScrollbar.height = @getHorizontalScrollbarHeight()
@state.verticalScrollbar.width = @getVerticalScrollbarWidth()
contentWidth = @computeContentWidth()
contentHeight = @computeContentHeight()
clientWidthWithoutVerticalScrollbar = @getContentFrameWidth()
clientWidthWithVerticalScrollbar = clientWidthWithoutVerticalScrollbar - @getVerticalScrollbarWidth()
clientHeightWithoutHorizontalScrollbar = @getHeight()
clientHeightWithHorizontalScrollbar = clientHeightWithoutHorizontalScrollbar - @getHorizontalScrollbarHeight()
@state.horizontalScrollbar.visible =
horizontalScrollbarVisible =
contentWidth > clientWidthWithoutVerticalScrollbar or
contentWidth > clientWidthWithVerticalScrollbar and contentHeight > clientHeightWithoutHorizontalScrollbar
@state.verticalScrollbar.visible =
verticalScrollbarVisible =
contentHeight > clientHeightWithoutHorizontalScrollbar or
contentHeight > clientHeightWithHorizontalScrollbar and contentWidth > clientWidthWithoutVerticalScrollbar
@state.horizontalScrollbar.visible = horizontalScrollbarVisible
@state.horizontalScrollbar.height = @getHorizontalScrollbarHeight()
@state.horizontalScrollbar.right = if verticalScrollbarVisible then @getVerticalScrollbarWidth() else 0
@state.verticalScrollbar.visible = verticalScrollbarVisible
@state.verticalScrollbar.width = @getVerticalScrollbarWidth()
@state.verticalScrollbar.bottom = if horizontalScrollbarVisible then @getHorizontalScrollbarHeight() else 0
@emitter.emit 'did-update-state'
updateContentState: ->