From da5ee3fa8623ab3023634462bcd7aea74e505a91 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 27 Jan 2015 18:34:17 -0700 Subject: [PATCH] Add TextEditorPresenter::state.mousewheelScreenRow --- spec/text-editor-presenter-spec.coffee | 35 ++++++++++++++++++++++++++ src/text-editor-presenter.coffee | 9 +++++++ 2 files changed, 44 insertions(+) diff --git a/spec/text-editor-presenter-spec.coffee b/spec/text-editor-presenter-spec.coffee index 5345f32ca..fecef4381 100644 --- a/spec/text-editor-presenter-spec.coffee +++ b/spec/text-editor-presenter-spec.coffee @@ -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", -> diff --git a/src/text-editor-presenter.coffee b/src/text-editor-presenter.coffee index b250cc6bd..85ca3866f 100644 --- a/src/text-editor-presenter.coffee +++ b/src/text-editor-presenter.coffee @@ -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()