diff options
author | bobzel <zzzman@gmail.com> | 2022-03-24 10:23:53 -0400 |
---|---|---|
committer | bobzel <zzzman@gmail.com> | 2022-03-24 10:23:53 -0400 |
commit | c534619229b0f1b7d1ef5606d76f6e4829743379 (patch) | |
tree | 3cc3dc8211e64598c4fa50e6709b5cd8d5e31049 | |
parent | 0e965ed78222ffbb87489c40b32c7dbdf4cbe0d5 (diff) |
fixed scroll location of webpages when activated for first time.
-rw-r--r-- | src/client/views/nodes/WebBox.tsx | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/client/views/nodes/WebBox.tsx b/src/client/views/nodes/WebBox.tsx index e6acddf23..3e3a6cfa5 100644 --- a/src/client/views/nodes/WebBox.tsx +++ b/src/client/views/nodes/WebBox.tsx @@ -103,6 +103,14 @@ export class WebBox extends ViewBoxAnnotatableComponent<ViewBoxAnnotatableProps } return true; } + setScrollPos = (pos: number) => { + if (!this._outerRef.current || this._outerRef.current.scrollHeight < pos) { + setTimeout(() => this.setScrollPos(pos), 250); + } else { + this._outerRef.current.scrollTop = pos; + this._initialScroll = undefined; + } + } async componentDidMount() { this.props.setContentView?.(this); // this tells the DocumentView that this WebBox is the "content" of the document. this allows the DocumentView to call WebBox relevant methods to configure the UI (eg, show back/forward buttons) @@ -118,11 +126,8 @@ export class WebBox extends ViewBoxAnnotatableComponent<ViewBoxAnnotatableProps this._webPageHasBeenRendered = true; setTimeout(action(() => { this._scrollHeight = Math.max(this.scrollHeight, this._iframe?.contentDocument?.body.scrollHeight || 0); - if (this._initialScroll !== undefined && this._outerRef.current) { - setTimeout(() => { - this._outerRef.current!.scrollTop = this._initialScroll!; - this._initialScroll = undefined; - }); + if (this._initialScroll !== undefined) { + this.setScrollPos(this._initialScroll); } })); } else if (!this.props.isContentActive() && |