Initial naive implementation of smooth scroll

This commit is contained in:
Florian Mounier
2015-04-10 18:18:06 +02:00
parent 6e7e222370
commit 3afebe4be0
6 changed files with 81 additions and 10 deletions

View File

@@ -0,0 +1,24 @@
document.addEventListener 'DOMContentLoaded', ->
return
req = null
butterfly.native_scroll_to = (scroll=-1) ->
e = butterfly.parent
cancelAnimationFrame req if req
if scroll is -1 or (
scroll > e.scrollHeight - e.getBoundingClientRect().height)
scroll = e.scrollHeight - e.getBoundingClientRect().height
diff = scroll - e.scrollTop
return if diff is 0
step = diff / 25
scroll_step = ->
if Math.abs(e.scrollTop - scroll) < Math.abs(step)
e.scrollTop = scroll
else
e.scrollTop += step
req = requestAnimationFrame scroll_step
req = requestAnimationFrame scroll_step

View File

@@ -461,8 +461,7 @@ class Terminal
for l, html of @html
@element.insertBefore(html, @children[l])
@html = {}
@parent.scrollTop = @parent.scrollHeight
@native_scroll_to()
_cursorBlink: ->
@cursorState ^= 1
@@ -536,9 +535,14 @@ class Terminal
@updateRange @scrollTop
@updateRange @scrollBottom
native_scroll_to: (scroll=-1) ->
if scroll is -1
scroll = @parent.scrollHeight - @parent.getBoundingClientRect().height
@parent.scrollTop = scroll
scroll_display: (disp) ->
if @native_scroll
@parent.scrollTop += disp * @char_size.height
@native_scroll_to @parent.scrollTop + disp * @char_size.height
else
@ydisp += disp
if @ydisp > @ybase