mirror of
https://gh-proxy.org/https://github.com/klinsmaya/multica.git
synced 2026-11-10 10:26:46 +08:00
Bridge the sandboxed HTML-attachment iframe's scroll position into the per-tab scroll memento so a long report returns to where you left it after an in-app tab switch. The preview scrolls inside `sandbox="allow-scripts"` (no `allow-same-origin`), so the parent cannot read its `scrollY`; an injected shim reports it via `postMessage` and a content fingerprint invalidates a stale offset when the attachment changes. Verified: typecheck 6/6 tasks, views Vitest 36/36, desktop Vitest 85/85, iframe-scroll-bridge Playwright spec 6/6 on both system Chrome and bundled Chromium. Known follow-up: a tab switch during the attachment's loading window still erases the saved offset (equivalent to pre-fix behavior, not a regression). Fixes #6405
17 lines
657 B
TypeScript
17 lines
657 B
TypeScript
/**
|
|
* DJB2 string hash — 32-bit unsigned, rendered as base36.
|
|
*
|
|
* Extracted from `rich-content/mounted-block-registry.ts` (same cheap,
|
|
* synchronous hash used by the Mermaid layout cache). Used by the HTML
|
|
* attachment preview to derive a `contentKey` fingerprint of the rendered
|
|
* text so that scroll restoration can detect when the attachment's content
|
|
* changed (re-upload to the same id) and refuse to restore a stale offset.
|
|
*/
|
|
export function hashString(source: string): string {
|
|
let hash = 5381;
|
|
for (let i = 0; i < source.length; i++) {
|
|
hash = ((hash << 5) + hash) ^ source.charCodeAt(i);
|
|
}
|
|
return (hash >>> 0).toString(36);
|
|
}
|