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");
|
return this.split("\n").map(it => it.trim()).join("\n");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
function addOnLoad(fun) {
|
function addOnLoad(fun) {
|
||||||
const oldOnLoad = window.onload || (() => {
|
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) {
|
function q(query) {
|
||||||
return document.querySelector(query);
|
return document.querySelector(query);
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,9 +144,11 @@ class Terminal {
|
||||||
switch (e.key.toLowerCase()) {
|
switch (e.key.toLowerCase()) {
|
||||||
case "arrowup":
|
case "arrowup":
|
||||||
this.inputText = this._inputHistory.previousEntry();
|
this.inputText = this._inputHistory.previousEntry();
|
||||||
|
window.setTimeout(() => moveCaretToEndOf(this._input), 0);
|
||||||
break;
|
break;
|
||||||
case "arrowdown":
|
case "arrowdown":
|
||||||
this.inputText = this._inputHistory.nextEntry();
|
this.inputText = this._inputHistory.nextEntry();
|
||||||
|
window.setTimeout(() => moveCaretToEndOf(this._input), 0);
|
||||||
break;
|
break;
|
||||||
case "l":
|
case "l":
|
||||||
if (e.ctrlKey) {
|
if (e.ctrlKey) {
|
||||||
|
|
Loading…
Reference in New Issue