fix browser not scrolling to ScrollTargets

This commit is contained in:
Aran-Fey
2024-04-27 17:38:23 +02:00
parent 510aa76177
commit 9b993e84ce
3 changed files with 25 additions and 3 deletions

View File

@@ -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 {

View File

@@ -1,3 +1,5 @@
import { componentsByElement } from './componentManagement';
export class AsyncQueue<T> {
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();
}

View File

@@ -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",