Preserve line numbers in presenter based on ::mouseWheelScreenRow

This commit is contained in:
Nathan Sobo
2015-01-28 16:24:54 -07:00
parent 35d3690088
commit 37a040a620
2 changed files with 30 additions and 0 deletions

View File

@@ -1258,6 +1258,28 @@ describe "TextEditorPresenter", ->
expectValues lineNumberStateForScreenRow(presenter, 7), {bufferRow: 7}
expect(lineNumberStateForScreenRow(presenter, 8)).toBeUndefined()
it "does not remove out-of-view line numbers corresponding to ::mouseWheelScreenRow until ::stoppedScrollingDelay elapses", ->
presenter = new TextEditorPresenter(model: editor, clientHeight: 25, scrollTop: 0, lineHeight: 10, lineOverdrawMargin: 1, stoppedScrollingDelay: 200)
expect(lineNumberStateForScreenRow(presenter, 0)).toBeDefined()
expect(lineNumberStateForScreenRow(presenter, 4)).toBeDefined()
expect(lineNumberStateForScreenRow(presenter, 5)).toBeUndefined()
presenter.setMouseWheelScreenRow(0)
expectStateUpdate presenter, -> presenter.setScrollTop(35)
expect(lineNumberStateForScreenRow(presenter, 0)).toBeDefined()
expect(lineNumberStateForScreenRow(presenter, 1)).toBeUndefined()
expect(lineNumberStateForScreenRow(presenter, 7)).toBeDefined()
expect(lineNumberStateForScreenRow(presenter, 8)).toBeUndefined()
expectStateUpdate presenter, -> advanceClock(200)
expect(lineNumberStateForScreenRow(presenter, 0)).toBeUndefined()
expect(lineNumberStateForScreenRow(presenter, 1)).toBeUndefined()
expect(lineNumberStateForScreenRow(presenter, 7)).toBeDefined()
expect(lineNumberStateForScreenRow(presenter, 8)).toBeUndefined()
describe ".decorationClasses", ->
it "adds decoration classes to the relevant line number state objects, both initially and when decorations change", ->
marker1 = editor.markBufferRange([[4, 0], [6, 2]], invalidate: 'touch')

View File

@@ -233,6 +233,13 @@ class TextEditorPresenter
@state.gutter.lineNumbers[id] = {screenRow, bufferRow, softWrapped, top, decorationClasses, foldable}
visibleLineNumberIds[id] = true
if @getMouseWheelScreenRow()? and not startRow <= @getMouseWheelScreenRow() < endRow
screenRow = @getMouseWheelScreenRow()
top = screenRow * @getLineHeight()
bufferRow = @model.bufferRowForScreenRow(screenRow)
@state.gutter.lineNumbers[id] = {screenRow, bufferRow, top}
visibleLineNumberIds[bufferRow] = true
for id of @state.gutter.lineNumbers
delete @state.gutter.lineNumbers[id] unless visibleLineNumberIds[id]
@@ -372,6 +379,7 @@ class TextEditorPresenter
if @getMouseWheelScreenRow()?
@mouseWheelScreenRow = null
@updateLinesState()
@updateLineNumbersState()
else
@emitter.emit 'did-update-state'