mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-20 15:37:46 +03:00
Preserve lines in TextEditorPresenter based on ::mouseWheelScreenRow
This commit is contained in:
parent
578a76ba6b
commit
35d3690088
@ -77,41 +77,6 @@ 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", ->
|
||||
@ -399,6 +364,40 @@ describe "TextEditorPresenter", ->
|
||||
tokens: line3.tokens
|
||||
}
|
||||
|
||||
it "does not remove out-of-view lines corresponding to ::mouseWheelScreenRow until ::stoppedScrollingDelay elapses", ->
|
||||
presenter = new TextEditorPresenter(model: editor, clientHeight: 25, scrollTop: 0, lineHeight: 10, lineOverdrawMargin: 1, stoppedScrollingDelay: 200)
|
||||
|
||||
expect(lineStateForScreenRow(presenter, 0)).toBeDefined()
|
||||
expect(lineStateForScreenRow(presenter, 4)).toBeDefined()
|
||||
expect(lineStateForScreenRow(presenter, 5)).toBeUndefined()
|
||||
|
||||
presenter.setMouseWheelScreenRow(0)
|
||||
expectStateUpdate presenter, -> presenter.setScrollTop(35)
|
||||
|
||||
expect(lineStateForScreenRow(presenter, 0)).toBeDefined()
|
||||
expect(lineStateForScreenRow(presenter, 1)).toBeUndefined()
|
||||
expect(lineStateForScreenRow(presenter, 7)).toBeDefined()
|
||||
expect(lineStateForScreenRow(presenter, 8)).toBeUndefined()
|
||||
|
||||
expectStateUpdate presenter, -> advanceClock(200)
|
||||
|
||||
expect(lineStateForScreenRow(presenter, 0)).toBeUndefined()
|
||||
expect(lineStateForScreenRow(presenter, 1)).toBeUndefined()
|
||||
expect(lineStateForScreenRow(presenter, 7)).toBeDefined()
|
||||
expect(lineStateForScreenRow(presenter, 8)).toBeUndefined()
|
||||
|
||||
it "does not preserve on-screen lines even if they correspond to ::mouseWheelScreenRow", ->
|
||||
presenter = new TextEditorPresenter(model: editor, clientHeight: 25, scrollTop: 0, lineHeight: 10, lineOverdrawMargin: 1, stoppedScrollingDelay: 200)
|
||||
oldLine3 = editor.tokenizedLineForScreenRow(6)
|
||||
|
||||
presenter.setMouseWheelScreenRow(3)
|
||||
|
||||
expectStateUpdate presenter, -> editor.getBuffer().insert([3, Infinity], 'xyz')
|
||||
newLine3 = editor.tokenizedLineForScreenRow(3)
|
||||
|
||||
expect(presenter.state.content.lines[oldLine3.id]).toBeUndefined()
|
||||
expect(presenter.state.content.lines[newLine3.id]).toBeDefined()
|
||||
|
||||
describe "[lineId]", -> # line state objects
|
||||
it "includes the .endOfLineInvisibles if the editor.showInvisibles config option is true", ->
|
||||
editor.setText("hello\nworld\r\n")
|
||||
|
@ -50,7 +50,6 @@ class TextEditorPresenter
|
||||
buildState: ->
|
||||
@state =
|
||||
scrollingVertically: false
|
||||
mouseWheelScreenRow: null
|
||||
content:
|
||||
blinkCursorsOff: false
|
||||
lines: {}
|
||||
@ -97,6 +96,11 @@ class TextEditorPresenter
|
||||
@buildLineState(row, line)
|
||||
row++
|
||||
|
||||
if @getMouseWheelScreenRow()? and not startRow <= @getMouseWheelScreenRow() < endRow
|
||||
preservedLine = @model.tokenizedLineForScreenRow(@getMouseWheelScreenRow())
|
||||
visibleLineIds[preservedLine.id] = true
|
||||
@updateLineState(@getMouseWheelScreenRow(), preservedLine)
|
||||
|
||||
for id, line of @state.content.lines
|
||||
unless visibleLineIds.hasOwnProperty(id)
|
||||
delete @state.content.lines[id]
|
||||
@ -361,14 +365,15 @@ 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'
|
||||
if @getMouseWheelScreenRow()?
|
||||
@mouseWheelScreenRow = null
|
||||
@updateLinesState()
|
||||
else
|
||||
@emitter.emit 'did-update-state'
|
||||
|
||||
getScrollTop: -> @scrollTop
|
||||
|
||||
@ -418,7 +423,6 @@ class TextEditorPresenter
|
||||
getLineHeight: -> @lineHeight
|
||||
|
||||
setMouseWheelScreenRow: (@mouseWheelScreenRow) ->
|
||||
@state.mouseWheelScreenRow = @mouseWheelScreenRow if @state.scrollingVertically
|
||||
|
||||
getMouseWheelScreenRow: -> @mouseWheelScreenRow
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user