mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-20 15:37:46 +03:00
Track horizontal/vertical scrollbar height/width in presenter
This commit is contained in:
parent
9de8ab949f
commit
1b5be9aef8
@ -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", ->
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user