mirror of
https://github.com/rxi/lovebird.git
synced 2024-12-09 01:04:22 +00:00
Changed up/down keys on inputbox to always set cursor to end
This commit is contained in:
parent
8029a07aaa
commit
fe2e607baa
10
lovebird.lua
10
lovebird.lua
@ -160,8 +160,8 @@ end
|
||||
<div id="output"> <?lua echo(lovebird.buffer) ?> </div>
|
||||
<div id="input">
|
||||
<form method="post"
|
||||
onkeydown="onInputKeyDown(event);"
|
||||
onsubmit="onInputSubmit(); return false">
|
||||
onkeydown="return onInputKeyDown(event);"
|
||||
onsubmit="onInputSubmit(); return false;">
|
||||
<input id="inputbox" name="input" type="text"></input>
|
||||
</form>
|
||||
</div>
|
||||
@ -223,17 +223,19 @@ end
|
||||
inputHistory.index = 0;
|
||||
var onInputKeyDown = function(e) {
|
||||
var key = e.which || e.keyCode;
|
||||
if (key != 38 && key != 40) return true;
|
||||
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] || "";
|
||||
}
|
||||
b.value = inputHistory[inputHistory.index] || "";
|
||||
b.selectionStart = b.value.length;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Output buffer and status */
|
||||
|
Loading…
Reference in New Issue
Block a user