From 5ec18ba043768208dbeacfe0b0c8acf53c81736a Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Wed, 14 Dec 2022 17:20:36 +0100 Subject: fix(frontend): do not scroll initially Make sure the CodeMirror DOM is fully ready before inserting a spacer element for overscroll behavior. --- subprojects/frontend/src/editor/scrollbarViewPlugin.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'subprojects/frontend') diff --git a/subprojects/frontend/src/editor/scrollbarViewPlugin.ts b/subprojects/frontend/src/editor/scrollbarViewPlugin.ts index 8f165e89..f54251a9 100644 --- a/subprojects/frontend/src/editor/scrollbarViewPlugin.ts +++ b/subprojects/frontend/src/editor/scrollbarViewPlugin.ts @@ -238,6 +238,8 @@ export default function scrollbarViewPlugin( let gutters: Element | undefined; + let firstRun = true; + let firstRunTimeout: number | undefined; let requested = false; let rebuildRequested = false; @@ -260,7 +262,18 @@ export default function scrollbarViewPlugin( const { scrollTop, scrollLeft, scrollWidth } = scrollDOM; const scrollHeight = view.contentHeight + scrollerHeight - view.defaultLineHeight; - spacer.style.minHeight = `${scrollHeight}px`; + if (firstRun) { + if (firstRunTimeout !== undefined) { + clearTimeout(firstRunTimeout); + } + // @ts-expect-error `@types/node` typings should not be in effect here. + firstRunTimeout = setTimeout(() => { + spacer.style.minHeight = `${scrollHeight}px`; + firstRun = false; + }, 0); + } else { + spacer.style.minHeight = `${scrollHeight}px`; + } gutterWidth = gutters?.clientWidth ?? 0; let trackYHeight = scrollerHeight; -- cgit v1.2.3-54-g00ecf