forked from tools/josh
1
0
Fork 0

Move caret to end after navigating history

This commit is contained in:
Florine W. Dekker 2018-11-29 01:38:04 +01:00
parent 2db415c963
commit ba9a97fe0a
Signed by: FWDekker
GPG Key ID: B1B567AF58D6EE0F
2 changed files with 13 additions and 0 deletions

View File

@ -20,6 +20,7 @@ String.prototype.trimLines = function () {
return this.split("\n").map(it => it.trim()).join("\n");
};
function addOnLoad(fun) {
const oldOnLoad = window.onload || (() => {
});
@ -30,6 +31,16 @@ function addOnLoad(fun) {
});
}
function moveCaretToEndOf(element) {
const range = document.createRange();
range.selectNodeContents(element);
range.collapse(false);
const selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
}
function q(query) {
return document.querySelector(query);
}

View File

@ -144,9 +144,11 @@ class Terminal {
switch (e.key.toLowerCase()) {
case "arrowup":
this.inputText = this._inputHistory.previousEntry();
window.setTimeout(() => moveCaretToEndOf(this._input), 0);
break;
case "arrowdown":
this.inputText = this._inputHistory.nextEntry();
window.setTimeout(() => moveCaretToEndOf(this._input), 0);
break;
case "l":
if (e.ctrlKey) {