| ... | ... | @@ -15,6 +15,8 @@ |
| 15 | 15 | return response.arrayBuffer(); |
| 16 | 16 | }); |
| 17 | 17 | var wasm_exports = null; |
| 18 | var curNavSearch = null; |
| 19 | var curNavLocation = null; |
| 18 | 20 | |
| 19 | 21 | const text_decoder = new TextDecoder(); |
| 20 | 22 | const text_encoder = new TextEncoder(); |
| ... | ... | @@ -47,11 +49,52 @@ |
| 47 | 49 | wasm_array.set(js_array); |
| 48 | 50 | wasm_exports.unpack(ptr, js_array.length); |
| 49 | 51 | |
| 52 | window.addEventListener('popstate', onPopState, false); |
| 53 | onHashChange(null); |
| 54 | |
| 50 | 55 | domStatus.textContent = "Waiting for server to send source location metadata..."; |
| 51 | 56 | connectWebSocket(); |
| 52 | 57 | }); |
| 53 | 58 | }); |
| 54 | 59 | |
| 60 | function onPopState(ev) { |
| 61 | onHashChange(ev.state); |
| 62 | } |
| 63 | |
| 64 | function onHashChange(state) { |
| 65 | history.replaceState({}, ""); |
| 66 | navigate(location.hash); |
| 67 | if (state == null) window.scrollTo({top: 0}); |
| 68 | } |
| 69 | |
| 70 | function navigate(location_hash) { |
| 71 | curNavLocation = null; |
| 72 | curNavSearch = null; |
| 73 | |
| 74 | if (location_hash.length > 1 && location_hash[0] === '#') { |
| 75 | const query = location_hash.substring(1); |
| 76 | const qpos = query.indexOf("?"); |
| 77 | let nonSearchPart; |
| 78 | if (qpos === -1) { |
| 79 | nonSearchPart = query; |
| 80 | } else { |
| 81 | nonSearchPart = query.substring(0, qpos); |
| 82 | curNavSearch = decodeURIComponent(query.substring(qpos + 1)); |
| 83 | } |
| 84 | |
| 85 | if (nonSearchPart.length > 0) { |
| 86 | curNavLocation = nonSearchPart; |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | render(); |
| 91 | |
| 92 | if (curNavLocation != null) { |
| 93 | // TODO |
| 94 | // scrollToSourceLocation(findSourceLocationIndex(curNavLocation)); |
| 95 | } |
| 96 | } |
| 97 | |
| 55 | 98 | function connectWebSocket() { |
| 56 | 99 | const host = window.document.location.host; |
| 57 | 100 | const pathname = window.document.location.pathname; |
| ... | ... | @@ -104,8 +147,9 @@ |
| 104 | 147 | domStatus.classList.add("hidden"); |
| 105 | 148 | domSectSource.classList.add("hidden"); |
| 106 | 149 | |
| 107 | | // TODO this is temporary debugging data |
| 108 | | renderSource("/home/andy/dev/zig/lib/std/zig/tokenizer.zig"); |
| 150 | if (curNavLocation != null) { |
| 151 | renderSource(curNavLocation.split(":")[0]); |
| 152 | } |
| 109 | 153 | } |
| 110 | 154 | |
| 111 | 155 | function renderStats() { |
| ... | ... | @@ -122,7 +166,7 @@ |
| 122 | 166 | resizeDomList(domEntryPointsList, entryPoints.length, "<li></li>"); |
| 123 | 167 | for (let i = 0; i < entryPoints.length; i += 1) { |
| 124 | 168 | const liDom = domEntryPointsList.children[i]; |
| 125 | | liDom.innerText = unwrapString(wasm_exports.sourceLocationLinkHtml(entryPoints[i])); |
| 169 | liDom.innerHTML = unwrapString(wasm_exports.sourceLocationLinkHtml(entryPoints[i])); |
| 126 | 170 | } |
| 127 | 171 | |
| 128 | 172 | |