Scroll editor using css 'top' property instead of scrollTop

This commit is contained in:
Corey Johnson 2012-06-11 15:12:09 -07:00
parent 9a5c252c85
commit e2bd646e0f
2 changed files with 21 additions and 2 deletions

View File

@ -292,6 +292,25 @@ describe "Editor", ->
editor.loadNextEditSession()
expect(editor.buffer.path).toBe "2"
it "restores scroll postion of edit session", ->
editor.attachToDom(heightInLines: 12)
buffer1 = editor.buffer
firstScrollTop = editor.scrollView.scrollTop()
buffer2 = new Buffer(require.resolve('fixtures/two-hundred.txt'))
editor.setBuffer(buffer2)
editor.moveCursorToBottom()
secondScrollTop = editor.scrollView.scrollTop()
expect(firstScrollTop).not.toEqual secondScrollTop
editor.loadNextEditSession()
expect(editor.buffer.path).toBe buffer1.path
expect(editor.scrollView.scrollTop()).toBe firstScrollTop
editor.loadNextEditSession()
expect(editor.buffer.path).toBe buffer2.path
expect(editor.scrollView.scrollTop()).toBe secondScrollTop
describe ".loadPreviousEditSession()", ->
it "loads the next editor state and wraps to beginning when end is reached", ->
buffer0 = new Buffer("0")

View File

@ -285,7 +285,7 @@ class Editor extends View
scrollTop: (scrollTop, options) ->
return @cachedScrollTop or 0 unless scrollTop?
maxScrollTop = @scrollView.prop('scrollHeight') - @scrollView.height()
maxScrollTop = @verticalScrollbar.prop('scrollHeight') - @verticalScrollbar.height()
scrollTop = Math.floor(Math.min(maxScrollTop, Math.max(0, scrollTop)))
return if scrollTop == @cachedScrollTop
@ -293,7 +293,7 @@ class Editor extends View
@updateRenderedLines() if @attached
@scrollView.scrollTop(scrollTop)
@renderedLines.css('top', -scrollTop)
@gutter.scrollTop(scrollTop)
if options?.adjustVerticalScrollbar ? true
@verticalScrollbar.scrollTop(scrollTop)