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="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 */
|
||||||
|
Loading…
Reference in New Issue
Block a user