Fix overly sticky auto-scroll behavior (#4382) The problem: Auto-scroll is overly sticky. While a generated message is streaming in, it is almost impossible to cancel the auto-scroll behavior by scrolling up, it just snaps back down. The reason is that the 'wheel' and 'touchmove' events trigger before the scroll position is updated. So the scrollIsAtBottom value never becomes false. That is, unless the user manages to scroll up quick enough to beat the call to scrollChatToBottom() in onProgressStreaming(). The 'scroll' event is better because it fires slightly later in the scroll behavior. This makes canceling auto-scroll by scrolling up much more reliable. Making auto-scroll cancelling more reliable has the side effect that resuming auto-scroll becomes harder. To even this out, this change slightly increases the tolerance for resuming auto-scroll to 5 pixels. This is small enough to be generally unnoticeable but significantly easier to hit than the previous 1 pixel. I tested this change in * Firefox on Linux * Chrome on Linux * Firefox on Android * Chrome on Android In all cases, the auto-scroll behavior is greatly improved: * While auto-scrolling, scrolling a little bit up immediately cancels the auto-scroll behavior. * Scrolling all the way down resumes the auto-scroll behavior.
Signed| @@ -9549,7 +9549,7 @@ jQuery(async function () { | |||
| 9549 | return; | 9549 | return; |
| 9550 | } | 9550 | } |
| 9551 | 9551 | ||
| 9552 | const scrollIsAtBottom = Math.abs(chatElementScroll.scrollHeight - chatElementScroll.clientHeight - chatElementScroll.scrollTop) < 1; | 9552 | const scrollIsAtBottom = Math.abs(chatElementScroll.scrollHeight - chatElementScroll.clientHeight - chatElementScroll.scrollTop) < 5; |
| 9553 | 9553 | ||
| 9554 | // Resume autoscroll if the user scrolls to the bottom | 9554 | // Resume autoscroll if the user scrolls to the bottom |
| 9555 | if (scrollLock && scrollIsAtBottom) { | 9555 | if (scrollLock && scrollIsAtBottom) { |
| @@ -9561,8 +9561,7 @@ jQuery(async function () { | |||
| 9561 | scrollLock = true; | 9561 | scrollLock = true; |
| 9562 | } | 9562 | } |
| 9563 | }; | 9563 | }; |
| 9564 | chatElementScroll.addEventListener('wheel', chatScrollHandler, { passive: true }); | 9564 | chatElementScroll.addEventListener('scroll', chatScrollHandler, { passive: true }); |
| 9565 | chatElementScroll.addEventListener('touchmove', chatScrollHandler, { passive: true }); | ||
| 9566 | 9565 | ||
| 9567 | $(document).on('click', '.mes', function () { | 9566 | $(document).on('click', '.mes', function () { |
| 9568 | //when a 'delete message' parent div is clicked | 9567 | //when a 'delete message' parent div is clicked |