diff --git a/src/assets/index.css b/src/assets/index.css index c66dfdb..63ae348 100644 --- a/src/assets/index.css +++ b/src/assets/index.css @@ -302,6 +302,7 @@ white-space: pre; user-select: text; font-family: monospace; + line-height: 1.25;/*forces all lines to be same height*/ } .mv-hexlabel { @@ -309,6 +310,12 @@ top: 180px; } +.mv-hexstickylabel { + position: sticky; + top: 50px; + bottom: 50px; +} + .mv-hex--select { background-color: #fff3; } diff --git a/src/utils.ts b/src/utils.ts index 0c032c8..045eac1 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -677,4 +677,12 @@ export class WeakRefMap { yield [k, v] as [K, V]; } } +} + +export function findParentElement(el: HTMLElement | null, cond: (el: HTMLElement) => boolean, fallback: HTMLElement | null = null) { + while (el) { + if (cond(el)) { return el; } + el = el.parentElement; + } + return fallback; } \ No newline at end of file diff --git a/src/viewer/maincomponents.tsx b/src/viewer/maincomponents.tsx index 9030fda..a6d8834 100644 --- a/src/viewer/maincomponents.tsx +++ b/src/viewer/maincomponents.tsx @@ -11,7 +11,7 @@ import { Openrs2CacheMeta, Openrs2CacheSource, validOpenrs2Caches } from "../cac import { DomWrap, UIScriptFile } from "./scriptsui"; import { DecodeErrorJson } from "../scripts/testdecode"; import prettyJson from "json-stringify-pretty-compact"; -import { delay, TypedEmitter } from "../utils"; +import { delay, findParentElement, TypedEmitter } from "../utils"; import { ParsedTexture } from "../3d/textures"; import { CacheDownloader } from "../cache/downloader"; import { parse } from "../opdecoder"; @@ -611,6 +611,18 @@ function FileDecodeErrorViewer(p: { file: string }) { let buffer = Buffer.from(err.originalFile, "hex"); return [err, buffer]; }, [p.file]); + + let clickstickylabel = (e: React.MouseEvent) => { + let target = findParentElement(e.currentTarget, el => el.tagName == "TR"); + let scrollparent = findParentElement(e.currentTarget, el => ["auto", "scroll"].includes(window.getComputedStyle(el).overflowY)); + if (!target || !scrollparent) { return; } + let scrollbounds = scrollparent.getBoundingClientRect(); + let bounds = target.getBoundingClientRect(); + let isbelow = (bounds.top + bounds.bottom) / 2 > (scrollbounds.top + scrollbounds.bottom) / 2; + let margin = scrollbounds.height / 4 + scrollparent.scrollTop += (isbelow ? bounds.bottom - margin : bounds.top - scrollbounds.height + margin); + } + return (
@@ -634,7 +646,7 @@ function FileDecodeErrorViewer(p: { file: string }) { {hexview.resulthex} {hexview.resultchrs} - {q.label} + {q.len > 16 * 20 ? {q.label} : q.label} ); })}