From 1b5be9aef835ecbf8ca1fb30ae4d27dceff904a5 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 28 Jan 2015 17:50:42 -0700 Subject: [PATCH] Track horizontal/vertical scrollbar height/width in presenter --- spec/text-editor-presenter-spec.coffee | 15 +++++++++++++++ src/text-editor-presenter.coffee | 18 ++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/spec/text-editor-presenter-spec.coffee b/spec/text-editor-presenter-spec.coffee index 7bd319895..6b73adc73 100644 --- a/spec/text-editor-presenter-spec.coffee +++ b/spec/text-editor-presenter-spec.coffee @@ -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", -> diff --git a/src/text-editor-presenter.coffee b/src/text-editor-presenter.coffee index 3530e4f81..cfdbe7399 100644 --- a/src/text-editor-presenter.coffee +++ b/src/text-editor-presenter.coffee @@ -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()