forked from tools/josh
Move caret to end after navigating history
This commit is contained in:
parent
2db415c963
commit
ba9a97fe0a
11
js/shared.js
11
js/shared.js
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue