Add TextEditorPresenter::state.mousewheelScreenRow

This commit is contained in:
Nathan Sobo
2015-01-27 18:34:17 -07:00
parent a88486e950
commit da5ee3fa86
2 changed files with 44 additions and 0 deletions

View File

@@ -77,6 +77,41 @@ describe "TextEditorPresenter", ->
expectStateUpdate presenter, -> advanceClock(100)
expect(presenter.state.scrollingVertically).toBe false
describe ".mousewheelScreenRow", ->
it "reflects the most recently assigned ::mousewheelScreenRow while .scrollingVertically is true", ->
presenter = new TextEditorPresenter(model: editor, scrollTop: 10, stoppedScrollingDelay: 200)
presenter.setMousewheelScreenRow(3)
expect(presenter.state.scrollingVertically).toBe false
expect(presenter.state.mousewheelScreenRow).toBeNull()
expectStateUpdate presenter, -> presenter.setScrollTop(0)
expect(presenter.state.scrollingVertically).toBe true
expect(presenter.state.mousewheelScreenRow).toBe 3
presenter.setMousewheelScreenRow(5)
expect(presenter.state.scrollingVertically).toBe true
expect(presenter.state.mousewheelScreenRow).toBe 5
advanceClock(100)
expect(presenter.state.scrollingVertically).toBe true
expect(presenter.state.mousewheelScreenRow).toBe 5
# should wait 200ms after the last scroll to clear
presenter.setScrollTop(10)
advanceClock(100) # so not yet...
expect(presenter.state.scrollingVertically).toBe true
expect(presenter.state.mousewheelScreenRow).toBe 5
expectStateUpdate presenter, -> advanceClock(100) # clear now
expect(presenter.state.scrollingVertically).toBe false
expect(presenter.state.mousewheelScreenRow).toBeNull()
# should be cleared even when we scroll again
expectStateUpdate presenter, -> presenter.setScrollTop(20)
expect(presenter.state.scrollingVertically).toBe true
expect(presenter.state.mousewheelScreenRow).toBeNull()
describe ".content", ->
describe ".scrollWidth", ->
it "is initialized as the max of the clientWidth and the width of the longest line", ->

View File

@@ -50,6 +50,7 @@ class TextEditorPresenter
buildState: ->
@state =
scrollingVertically: false
mousewheelScreenRow: null
content:
blinkCursorsOff: false
lines: {}
@@ -360,10 +361,13 @@ class TextEditorPresenter
@stoppedScrollingTimeoutId = null
@stoppedScrollingTimeoutId = setTimeout(@didStopScrolling.bind(this), @stoppedScrollingDelay)
@state.scrollingVertically = true
@state.mousewheelScreenRow = @getMousewheelScreenRow()
@emitter.emit 'did-update-state'
didStopScrolling: ->
@state.scrollingVertically = false
@state.mousewheelScreenRow = null
@mousewheelScreenRow = null
@emitter.emit 'did-update-state'
getScrollTop: -> @scrollTop
@@ -413,6 +417,11 @@ class TextEditorPresenter
getLineHeight: -> @lineHeight
setMousewheelScreenRow: (@mousewheelScreenRow) ->
@state.mousewheelScreenRow = @mousewheelScreenRow if @state.scrollingVertically
getMousewheelScreenRow: -> @mousewheelScreenRow
setBaseCharacterWidth: (@baseCharacterWidth) ->
@characterWidthsChanged()