From 8029a07aaa2ac398e34030514acd6ed31efac41c Mon Sep 17 00:00:00 2001 From: rxi Date: Sun, 13 Apr 2014 11:08:15 +0100 Subject: [PATCH] Added support for up/down keys on input box to recall past inputs --- lovebird.lua | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/lovebird.lua b/lovebird.lua index a7ac4a0..aa6eac6 100644 --- a/lovebird.lua +++ b/lovebird.lua @@ -159,7 +159,9 @@ end
-
+
@@ -206,10 +208,34 @@ end var req = new XMLHttpRequest(); req.open("POST", "/", true); req.send("input=" + encodeURIComponent(b.value)); + /* Do input history */ + if (b.value && inputHistory[0] != b.value) { + inputHistory.unshift(b.value); + } + inputHistory.index = -1; + /* Reset */ b.value = ""; refreshOutput(); } + /* Input box history */ + var inputHistory = []; + inputHistory.index = 0; + var onInputKeyDown = function(e) { + var key = e.which || e.keyCode; + var b = document.getElementById("inputbox"); + if (key == 38 && inputHistory.index < inputHistory.length - 1) { + /* Up key */ + inputHistory.index++; + b.value = inputHistory[inputHistory.index]; + } + if (key == 40 && inputHistory.index >= 0) { + /* Down key */ + inputHistory.index--; + b.value = inputHistory[inputHistory.index] || ""; + } + } + /* Output buffer and status */ var refreshOutput = function() { geturl("/buffer", function(text) {