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 (this.channel.historyLoading) {
const heightOld = el.scrollHeight - el.scrollTop;
this.isWaitingForNextTick = true;
this.$nextTick(() => {
this.isWaitingForNextTick = false;
el.scrollTop = el.scrollHeight - heightOld;
});
}
return;
}

View file

@ -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;
});
});