WIP: Don't allow impossibly high scroll top values.

It fixes the move to bottom issues, but breaks some other tests. Not sure why yet...
This commit is contained in:
Nathan Sobo 2012-06-04 21:57:10 -06:00
parent 3c2facc7be
commit 9cfbce826d
2 changed files with 7 additions and 4 deletions

View File

@ -8,7 +8,7 @@ $ = require 'jquery'
_ = require 'underscore'
fs = require 'fs'
describe "Editor", ->
fdescribe "Editor", ->
[rootView, buffer, editor, cachedLineHeight] = []
getLineHeight = ->
@ -72,7 +72,7 @@ describe "Editor", ->
newEditor.width(editor.width())
rootView.remove()
newEditor.attachToDom()
expect(newEditor.scrollTop()).toBe 1.5 * editor.lineHeight
expect(newEditor.scrollTop()).toBe editor.scrollTop()
expect(newEditor.scrollView.scrollLeft()).toBe 44
describe ".setBuffer(buffer)", ->
@ -701,7 +701,8 @@ describe "Editor", ->
expect(editor.renderedLines.find('.line').text()).toBe buffer.lineForRow(0)
describe "when autoscrolling at the end of the document", ->
xit "renders lines properly", ->
it "renders lines properly", ->
console.log editor.lineOverdraw
editor.setBuffer(new Buffer(require.resolve 'fixtures/two-hundred.txt'))
editor.attachToDom(heightInLines: 5.5)
expect(editor.renderedLines.find('.line').length).toBe 8

View File

@ -273,7 +273,9 @@ class Editor extends View
scrollTop: (scrollTop, options) ->
return @cachedScrollTop or 0 unless scrollTop?
scrollTop = Math.max(0, scrollTop)
maxScrollTop = @scrollView.prop('scrollHeight') - @scrollView.height()
scrollTop = Math.floor(Math.min(maxScrollTop, Math.max(0, scrollTop)))
return if scrollTop == @cachedScrollTop
@cachedScrollTop = scrollTop