Keep scroll position when scrolling up

This commit is contained in:
Pavel Djundik 2018-07-12 19:25:41 +03:00 committed by Pavel Djundik
parent dbe95fcc13
commit 499beb0257
2 changed files with 15 additions and 2 deletions

View File

@ -186,6 +186,16 @@ export default {
} }
if (el.scrollHeight - el.scrollTop - el.offsetHeight > 30) { 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; return;
} }

View File

@ -1,7 +1,7 @@
"use strict"; "use strict";
const socket = require("../socket"); const socket = require("../socket");
const {findChannel} = require("../vue"); const {vueApp, findChannel} = require("../vue");
socket.on("more", function(data) { socket.on("more", function(data) {
const channel = findChannel(data.chan); const channel = findChannel(data.chan);
@ -12,5 +12,8 @@ socket.on("more", function(data) {
channel.channel.moreHistoryAvailable = data.moreHistoryAvailable; channel.channel.moreHistoryAvailable = data.moreHistoryAvailable;
channel.channel.messages.unshift(...data.messages); channel.channel.messages.unshift(...data.messages);
vueApp.$nextTick(() => {
channel.channel.historyLoading = false; channel.channel.historyLoading = false;
});
}); });