From: Elijah Cohen Date: Sat, 11 Jan 2025 04:16:12 +0000 (-0600) Subject: added uparrow/downarrow history to web repl X-Git-Url: https://git.eli173.com/?a=commitdiff_plain;h=919ae2e92315b83da414271dffd62d166cc37d0e;p=klapaucius added uparrow/downarrow history to web repl --- diff --git a/web/setup.js b/web/setup.js index bb36d7a..2d466eb 100644 --- a/web/setup.js +++ b/web/setup.js @@ -13,11 +13,15 @@ var Module = { }; })(), }; +var hist = []; +var currhist = 0; document.getElementById("replform").addEventListener("submit", e => { e.preventDefault(); let outzone = document.getElementById("replout"); let inelt = document.createElement('div'); - let instr = e.target[0].value + let instr = e.target[0].value; + hist.unshift(instr); + currhist = 0; inelt.textContent += "<- " + instr + "\n"; inelt.addEventListener("click", (eclick) => { let replin = document.getElementById('replin'); @@ -41,6 +45,18 @@ document.getElementById("replform").addEventListener("submit", e => { outzone.appendChild(outelt); document.getElementById('replin').value = "" }); +document.getElementById('replin').addEventListener("keydown", e=> { + if(hist.length == 0) return; + if(e.key == "ArrowUp") { + currhist = Math.min(hist.length, currhist+1); + document.getElementById('replin').value = hist[currhist-1]; + } + if(e.key == "ArrowDown") { + currhist = Math.max(0, currhist-1); + document.getElementById('replin').value = currhist==0 ? "" : hist[currhist-1]; + } +}); + if('serviceWorker' in navigator) { console.log('registering');