Skip to content

Commit

Permalink
Merge pull request #1273 from HomerSp/fix-history-endless-scrolling
Browse files Browse the repository at this point in the history
Fix endless scrolling when scrolling through chat history
  • Loading branch information
averissimo committed Dec 10, 2020
2 parents a5f3764 + d50922b commit 035ce07
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
25 changes: 13 additions & 12 deletions src/ui/views/applayout.coffee
Expand Up @@ -27,12 +27,20 @@ onScroll = throttle 20, (ev) ->
el = ev.target
child = el.children[0]

# use the saved scroll value if we have one
if el.hasAttribute('scrolltop')
el.scrollTop = el.getAttribute('scrolltop')
el.removeAttribute('scrolltop')

# calculation to see whether we are at the bottom with a tolerance value
atbottom = (el.scrollTop + el.offsetHeight) >= (child.offsetHeight - 10)
action 'atbottom', atbottom

# check whether we are at the top with a tolerance value
attop = el.scrollTop <= (el.offsetHeight / 2)
if el.scrollTop < 0
attop = child.offsetHeight - el.offsetHeight + el.scrollTop <= el.offsetHeight / 2
else
attop = el.scrollTop <= (el.offsetHeight / 2)
action 'attop', attop

addClass = (el, cl) ->
Expand Down Expand Up @@ -131,18 +139,11 @@ do ->
return last

exp.recordMainPos = ->
el = lastVisibleMessage()
id = el?.id
return unless el and id
ofs = topof el
ofs = document.querySelector('.main').scrollTop

exp.adjustMainPos = ->
return unless id and ofs
el = document.getElementById id
nofs = topof el
# the size of the inserted elements
inserted = nofs - ofs
screl = document.querySelector('.main')
screl.scrollTop = screl.scrollTop + inserted
return unless ofs
document.querySelector('.main').scrollTop = ofs
document.querySelector('.main').setAttribute('scrolltop', ofs)
# reset
id = ofs = null
2 changes: 1 addition & 1 deletion src/ui/views/messages.coffee
Expand Up @@ -293,7 +293,7 @@ scrollToBottom = module.exports.scrollToBottom = ->
# ensure we're scrolled to bottom
el = document.querySelector('.main')
# to bottom
el.scrollTop = Number.MAX_SAFE_INTEGER
el.scrollTop = 0


ifpass = (t, f) -> if t then f else pass
Expand Down

0 comments on commit 035ce07

Please sign in to comment.