mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
Add TextEditorPresenter::state.mousewheelScreenRow
This commit is contained in:
@@ -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", ->
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user