mirror of
https://github.com/thelounge/thelounge
synced 2024-11-29 23:40:28 +00:00
Skip scroll event which is called after setting scrollTop
This commit is contained in:
parent
4a0f319e91
commit
893d59e7c4
1 changed files with 13 additions and 7 deletions
|
@ -51,8 +51,6 @@
|
|||
<script>
|
||||
require("intersection-observer");
|
||||
|
||||
const throttle = require("lodash/throttle");
|
||||
|
||||
const constants = require("../js/constants");
|
||||
const clipboard = require("../js/clipboard");
|
||||
import socket from "../js/socket";
|
||||
|
@ -159,14 +157,11 @@ export default {
|
|||
});
|
||||
}
|
||||
|
||||
this.channel.scrolledToBottom = true;
|
||||
this.jumpToBottom();
|
||||
});
|
||||
},
|
||||
mounted() {
|
||||
this.debouncedScroll = throttle(this.handleScroll, 100);
|
||||
|
||||
this.$refs.chat.addEventListener("scroll", this.debouncedScroll, {passive: true});
|
||||
this.$refs.chat.addEventListener("scroll", this.handleScroll, {passive: true});
|
||||
|
||||
this.$root.$on("resize", this.handleResize);
|
||||
|
||||
|
@ -181,7 +176,7 @@ export default {
|
|||
},
|
||||
beforeDestroy() {
|
||||
this.$root.$off("resize", this.handleResize);
|
||||
this.$refs.chat.removeEventListener("scroll", this.debouncedScroll);
|
||||
this.$refs.chat.removeEventListener("scroll", this.handleScroll);
|
||||
},
|
||||
destroyed() {
|
||||
if (this.historyObserver) {
|
||||
|
@ -262,6 +257,7 @@ export default {
|
|||
this.isWaitingForNextTick = true;
|
||||
this.$nextTick(() => {
|
||||
this.isWaitingForNextTick = false;
|
||||
this.skipNextScrollEvent = true;
|
||||
el.scrollTop = el.scrollHeight - heightOld;
|
||||
});
|
||||
}
|
||||
|
@ -276,6 +272,13 @@ export default {
|
|||
});
|
||||
},
|
||||
handleScroll() {
|
||||
// Setting scrollTop also triggers scroll event
|
||||
// We don't want to perform calculations for that
|
||||
if (this.skipNextScrollEvent) {
|
||||
this.skipNextScrollEvent = false;
|
||||
return;
|
||||
}
|
||||
|
||||
const el = this.$refs.chat;
|
||||
|
||||
if (!el) {
|
||||
|
@ -291,6 +294,9 @@ export default {
|
|||
}
|
||||
},
|
||||
jumpToBottom() {
|
||||
this.skipNextScrollEvent = true;
|
||||
this.channel.scrolledToBottom = true;
|
||||
|
||||
const el = this.$refs.chat;
|
||||
el.scrollTop = el.scrollHeight;
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue