From 499beb025700ae6b4c22a25e56ba75fed42d05d8 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Thu, 12 Jul 2018 19:25:41 +0300 Subject: [PATCH] Keep scroll position when scrolling up --- client/components/Chat.vue | 10 ++++++++++ client/js/socket-events/more.js | 7 +++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/client/components/Chat.vue b/client/components/Chat.vue index 8ff709a5..14df581d 100644 --- a/client/components/Chat.vue +++ b/client/components/Chat.vue @@ -186,6 +186,16 @@ export default { } if (el.scrollHeight - el.scrollTop - el.offsetHeight > 30) { + if (this.channel.historyLoading) { + const heightOld = el.scrollHeight - el.scrollTop; + + this.isWaitingForNextTick = true; + this.$nextTick(() => { + this.isWaitingForNextTick = false; + el.scrollTop = el.scrollHeight - heightOld; + }); + } + return; } diff --git a/client/js/socket-events/more.js b/client/js/socket-events/more.js index 8f6fe966..dc2d1ec2 100644 --- a/client/js/socket-events/more.js +++ b/client/js/socket-events/more.js @@ -1,7 +1,7 @@ "use strict"; const socket = require("../socket"); -const {findChannel} = require("../vue"); +const {vueApp, findChannel} = require("../vue"); socket.on("more", function(data) { const channel = findChannel(data.chan); @@ -12,5 +12,8 @@ socket.on("more", function(data) { channel.channel.moreHistoryAvailable = data.moreHistoryAvailable; channel.channel.messages.unshift(...data.messages); - channel.channel.historyLoading = false; + + vueApp.$nextTick(() => { + channel.channel.historyLoading = false; + }); });