Changed up/down keys on inputbox to always set cursor to end

This commit is contained in:
rxi 2014-04-13 12:19:04 +01:00
parent 8029a07aaa
commit fe2e607baa

View File

@ -160,8 +160,8 @@ end
<div id="output"> <?lua echo(lovebird.buffer) ?> </div> <div id="output"> <?lua echo(lovebird.buffer) ?> </div>
<div id="input"> <div id="input">
<form method="post" <form method="post"
onkeydown="onInputKeyDown(event);" onkeydown="return onInputKeyDown(event);"
onsubmit="onInputSubmit(); return false"> onsubmit="onInputSubmit(); return false;">
<input id="inputbox" name="input" type="text"></input> <input id="inputbox" name="input" type="text"></input>
</form> </form>
</div> </div>
@ -223,17 +223,19 @@ end
inputHistory.index = 0; inputHistory.index = 0;
var onInputKeyDown = function(e) { var onInputKeyDown = function(e) {
var key = e.which || e.keyCode; var key = e.which || e.keyCode;
if (key != 38 && key != 40) return true;
var b = document.getElementById("inputbox"); var b = document.getElementById("inputbox");
if (key == 38 && inputHistory.index < inputHistory.length - 1) { if (key == 38 && inputHistory.index < inputHistory.length - 1) {
/* Up key */ /* Up key */
inputHistory.index++; inputHistory.index++;
b.value = inputHistory[inputHistory.index];
} }
if (key == 40 && inputHistory.index >= 0) { if (key == 40 && inputHistory.index >= 0) {
/* Down key */ /* Down key */
inputHistory.index--; inputHistory.index--;
b.value = inputHistory[inputHistory.index] || "";
} }
b.value = inputHistory[inputHistory.index] || "";
b.selectionStart = b.value.length;
return false;
} }
/* Output buffer and status */ /* Output buffer and status */