]> git.eli173.com Git - klapaucius/commitdiff
added uparrow/downarrow history to web repl main
authorElijah Cohen <eli@eli173.com>
Sat, 11 Jan 2025 04:16:12 +0000 (22:16 -0600)
committerElijah Cohen <eli@eli173.com>
Sat, 11 Jan 2025 04:16:12 +0000 (22:16 -0600)
web/setup.js

index bb36d7a8897c7ed4b45e16d44cfa3ffa9f8819d1..2d466ebb700510c13bdaff71120db8e7c6acb8a2 100644 (file)
@@ -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');