From df2c0b108f58fec955f402994f2fbcea10dfbf67 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Thu, 7 Apr 2016 01:44:22 +0000 Subject: [PATCH] Added a rudimentary command history. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3190 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- core/client.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/core/client.js b/core/client.js index 1aa2b6e3..48adb918 100644 --- a/core/client.js +++ b/core/client.js @@ -4,11 +4,32 @@ var gHaveIndex = -1; var gSessionId; var gCredentials; var gErrorCount = 0; +var gCommandHistory = []; + +var kMaxCommandHistory = 16; function enter(event) { if (event.keyCode == 13) { + gCommandHistory.push(document.getElementById("input").value); + if (gCommandHistory.length > kMaxCommandHistory) { + gCommandHistory.shift(); + } send(); event.preventDefault(); + } else if (event.keyCode == 38) { + if (gCommandHistory.length) { + var input = document.getElementById("input"); + gCommandHistory.unshift(input.value); + input.value = gCommandHistory.pop(); + event.preventDefault(); + } + } else if (event.keyCode == 40) { + if (gCommandHistory.length) { + var input = document.getElementById("input"); + gCommandHistory.push(input.value); + input.value = gCommandHistory.shift(); + event.preventDefault(); + } } else if (event.keyCode == 186 && !event.metaKey && !event.altKey