From a3ad239b0924995765e0f9a8fdb1219a868f31b7 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Thu, 27 Jul 2023 15:25:25 +0200 Subject: [PATCH] Fixes #428 --- web/open_pages.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/web/open_pages.ts b/web/open_pages.ts index 608f1217..3b364567 100644 --- a/web/open_pages.ts +++ b/web/open_pages.ts @@ -17,11 +17,10 @@ export class OpenPages { const editorView = this.editorView; if (pageState) { // Restore state - editorView.scrollDOM.scrollTop = pageState!.scrollTop; try { editorView.dispatch({ selection: pageState.selection, - scrollIntoView: true, + // scrollIntoView: true, }); } catch { // This is fine, just go to the top @@ -30,6 +29,10 @@ export class OpenPages { scrollIntoView: true, }); } + setTimeout(() => { + // Next tick, to allow the editor to process the render + editorView.scrollDOM.scrollTop = pageState.scrollTop; + }); } else { editorView.scrollDOM.scrollTop = 0; editorView.dispatch({ @@ -45,8 +48,8 @@ export class OpenPages { this.openPages.set( currentPage, new PageState( - this.editorView!.scrollDOM.scrollTop, - this.editorView!.state.selection, + this.editorView.scrollDOM.scrollTop, + this.editorView.state.selection, ), ); }