diff --git a/frontend/code/componentManagement.ts b/frontend/code/componentManagement.ts index 1682fe84..b26dc531 100644 --- a/frontend/code/componentManagement.ts +++ b/frontend/code/componentManagement.ts @@ -37,7 +37,7 @@ import { PopupComponent } from './components/popup'; import { ProgressBarComponent } from './components/progressBar'; import { ProgressCircleComponent } from './components/progressCircle'; import { RectangleComponent } from './components/rectangle'; -import { reprElement } from './utils'; +import { reprElement, scrollToUrlFragment } from './utils'; import { RevealerComponent } from './components/revealer'; import { ScrollContainerComponent } from './components/scrollContainer'; import { ScrollTargetComponent } from './components/scrollTarget'; @@ -511,6 +511,12 @@ export function updateComponentStates( // Update the layout updateLayout(); + + // If this is the first time, check if there's an #url-fragment and scroll + // to it + if (rootComponentId !== null) { + scrollToUrlFragment(); + } } function canHaveKeyboardFocus(instance: ComponentBase): boolean { diff --git a/frontend/code/utils.ts b/frontend/code/utils.ts index f616fb6e..5416ba15 100644 --- a/frontend/code/utils.ts +++ b/frontend/code/utils.ts @@ -1,3 +1,5 @@ +import { componentsByElement } from './componentManagement'; + export class AsyncQueue { private waitingForValue: ((value: T) => void)[] = []; private values: T[] = []; @@ -105,3 +107,19 @@ export function copyToClipboard(text: string): void { document.execCommand('copy'); document.body.removeChild(textArea); } + +/// Checks if there's an #url-fragment, and if so, scrolls the corresponding +/// ScrollTarget into view +export function scrollToUrlFragment(): void { + let fragment = window.location.hash.substring(1); + if (!fragment) { + return; + } + + let element = document.getElementById(fragment); + if (element === null) { + return; + } + + element.scrollIntoView(); +} diff --git a/pyproject.toml b/pyproject.toml index c75e38eb..606ea0b1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -62,7 +62,6 @@ classifiers = [ "Topic :: Internet :: WWW/HTTP :: WSGI :: Application", "Topic :: Software Development :: Libraries :: Python Modules", ] -version = "0.1.0" [project.optional-dependencies] window = [ @@ -89,7 +88,6 @@ dev-dependencies = [ "black~=24.4.0", "coverage~=7.2.2", "pre-commit~=3.1.1", - "pyfakefs~=5.3.0", "pytest~=7.3.1", "pyright~=1.1.350", "requests~=2.31",