From 495ad6873fb322d4410ee51183d07e99c50e9b3f Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sun, 7 Sep 2025 10:57:57 +0200 Subject: [PATCH] Scroll locking --- page/src/components/output.tsx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/page/src/components/output.tsx b/page/src/components/output.tsx index beb8cabc..4dbf1918 100644 --- a/page/src/components/output.tsx +++ b/page/src/components/output.tsx @@ -181,6 +181,7 @@ export class Output extends React.Component { private listRef: React.RefObject; private resizeObserver: ResizeObserver; private scrollElement: HTMLDivElement | null | undefined; + private scrollActive: boolean = false; constructor(props: OutputProps) { super(props); @@ -189,6 +190,7 @@ export class Output extends React.Component { this.logLine = this.logLine.bind(this); this.logLines = this.logLines.bind(this); this.handleScroll = this.handleScroll.bind(this); + this.handleScrollEnd = this.handleScrollEnd.bind(this); this.updateDimensions = this.updateDimensions.bind(this); this.outputRef = React.createRef(); @@ -211,6 +213,10 @@ export class Output extends React.Component { } handleScroll(e: Event) { + if (this.scrollActive) { + return; + } + const threshold = 40; const element = e.target as HTMLElement; const { scrollTop, scrollHeight, clientHeight } = element; @@ -219,8 +225,14 @@ export class Output extends React.Component { this.setState({ autoScroll: isAtEnd }); } + handleScrollEnd(e: Event) { + this.scrollActive = false; + this.handleScroll(e); + } + unregisterScrollListener() { this.scrollElement?.removeEventListener("scroll", this.handleScroll); + this.scrollElement?.removeEventListener("scrollend", this.handleScrollEnd); } registerScrollListener(element: HTMLDivElement | null | undefined) { @@ -231,6 +243,7 @@ export class Output extends React.Component { this.unregisterScrollListener(); this.scrollElement = element; element?.addEventListener("scroll", this.handleScroll); + element?.addEventListener("scrollend", this.handleScrollEnd); } registerScrollOnList() { @@ -254,6 +267,7 @@ export class Output extends React.Component { scrollListToEnd() { if (this.listRef.current && this.state.lines.length > 0) { + this.scrollActive = true; this.listRef.current.scrollToRow({ index: this.state.lines.length - 1, behavior: "instant",