diff --git a/spec/text-editor-presenter-spec.coffee b/spec/text-editor-presenter-spec.coffee index 12dea85ec..cc7eba628 100644 --- a/spec/text-editor-presenter-spec.coffee +++ b/spec/text-editor-presenter-spec.coffee @@ -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", -> diff --git a/src/text-editor-presenter.coffee b/src/text-editor-presenter.coffee index 071b21403..7d2326a64 100644 --- a/src/text-editor-presenter.coffee +++ b/src/text-editor-presenter.coffee @@ -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: ->