mirror of
https://github.com/paradoxxxzero/butterfly.git
synced 2026-05-26 15:13:36 +00:00
Initial naive implementation of smooth scroll
This commit is contained in:
24
coffees/ext/smooth_scroll.coffee
Normal file
24
coffees/ext/smooth_scroll.coffee
Normal 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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user