From 8ef1fdee3f933d5528c54ddd089f73f8fc48704b Mon Sep 17 00:00:00 2001 From: Dougal Date: Mon, 8 Jan 2024 12:32:51 -0500 Subject: Fix bug in notebook refresh. We have much more state thatn --- lib/sort.dx | 16 +++++----------- static/index.ts | 36 ++++++++---------------------------- static/style.css | 3 ++- 3 files changed, 15 insertions(+), 40 deletions(-) diff --git a/lib/sort.dx b/lib/sort.dx index e61ee33a..5f712c3f 100644 --- a/lib/sort.dx +++ b/lib/sort.dx @@ -12,7 +12,7 @@ it's doing bubble / insertion sort with quadratic time cost. However, if it breaks the list in half recursively, it'll be doing parallel mergesort. Currently the Dex compiler will do the quadratic-time version. -def concat_table(leftin: a=>v, rightin: b=>v) -> (Either a b=>v) given (a|Ix, b|Ix, v) = +def concat_table(leftin: a=>v, rightin: b=>v) -> (Either a b=>v) given (a|Ix, b|Ix, v:Type) = for idx. case idx of Left i -> leftin[i] Right i -> rightin[i] @@ -50,17 +50,11 @@ def merge_sorted_lists(lx: List a, ly: List a) -> List a given (a|Ord) = newsize = nx + ny AsList _ $ unsafe_cast_table(to=Fin newsize, sorted) +# Warning: Has quadratic runtime cost for now. def sort(xs: n=>a) -> n=>a given (n|Ix, a|Ord) = - # Warning: Has quadratic runtime cost for now. - - xlists = for i:n. (AsList 1 [xs[i]]) - - # Merge sort monoid: - mempty = AsList 0 [] - mcombine = merge_sorted_lists - + xlists = each xs \x. to_list([x]) # reduce might someday recursively subdivide the problem. - AsList(_, r) = reduce mempty mcombine xlists + AsList(_, r) = reduce xlists mempty merge_sorted_lists unsafe_cast_table(to=n, r) def (+|)(i:n, delta:Nat) -> n given (n|Ix) = @@ -68,4 +62,4 @@ def (+|)(i:n, delta:Nat) -> n given (n|Ix) = from_ordinal $ select (i' >= size n) (size n -| 1) i' def is_sorted(xs:n=>a) -> Bool given (a|Ord, n|Ix) = - all for i. xs[i] <= xs[i +| 1] + all for i:n. xs[i] <= xs[i +| 1] diff --git a/static/index.ts b/static/index.ts index 11ee28fb..663a571d 100644 --- a/static/index.ts +++ b/static/index.ts @@ -358,39 +358,19 @@ function render(renderMode:RenderMode, jsonData:string) { source.onmessage = function(event) { const msg = JSON.parse(event.data); if (msg == "start") { - body.innerHTML = "" - cells.clear() - return + resetState() } else { processUpdates(msg) }};} } -const katexOptions = { - delimiters: [ - {left: "$$", right: "$$", display: true}, - {left: "\\[", right: "\\]", display: true}, - {left: "$", right: "$", display: false}, - {left: "\\(", right: "\\)", display: false} - ], - // Enable commands that load resources or change HTML attributes - // (e.g. hyperlinks): https://katex.org/docs/security.html. - trust: true -}; - -function renderLaTeX(root:Div) { - // // Render LaTeX equations in prose blocks via KaTeX, if available. - // // Skip rendering if KaTeX is unavailable. - // let renderMathInElement: any - // if (typeof renderMathInElement == 'undefined') { - // return; - // } - // // Render LaTeX equations in prose blocks via KaTeX. - // const proseBlocks = root.querySelectorAll(".prose-block"); - // Array.from(proseBlocks).map((proseBlock) => - // renderMathInElement(proseBlock, katexOptions) - // ); +function resetState() { + body.innerHTML = "" + hoverInfoDiv.innerHTML = "" + minimap.innerHTML = "" + orderedCells.length = 0 + curHighlights.length = 0 + cells.clear() } - // === hover system === const curHighlights : [Div, string][] = [] // HTML elements currently highlighted diff --git a/static/style.css b/static/style.css index 988b8cad..d7030bf1 100644 --- a/static/style.css +++ b/static/style.css @@ -77,7 +77,8 @@ body { /* span highlighting */ .highlight-error { - text-decoration: red wavy underline; + text-decoration: red underline; + text-decoration-thickness: 5px; text-decoration-skip-ink: none;} .highlight-group { background-color: yellow; } .highlight-scope { background-color: lightyellow; } -- cgit v1.2.3-70-g09d2