mirror of https://github.com/lus/pasty.git
Fix tab key behaviour
This commit is contained in:
parent
42a400ac19
commit
72b0a461e9
|
@ -62,8 +62,26 @@ async function loadPaste() {
|
|||
window.addEventListener("keydown", function (event) {
|
||||
if (event.keyCode != 9) return;
|
||||
event.preventDefault();
|
||||
input.value += " ";
|
||||
|
||||
insertTextAtCursor(input, " ");
|
||||
});
|
||||
}
|
||||
}
|
||||
spinner.surround(loadPaste);
|
||||
spinner.surround(loadPaste);
|
||||
|
||||
// 1:1 skid from https://stackoverflow.com/questions/7404366/how-do-i-insert-some-text-where-the-cursor-is
|
||||
function insertTextAtCursor(el, text) {
|
||||
var val = el.value, endIndex, range, doc = el.ownerDocument;
|
||||
if (typeof el.selectionStart == "number"
|
||||
&& typeof el.selectionEnd == "number") {
|
||||
endIndex = el.selectionEnd;
|
||||
el.value = val.slice(0, endIndex) + text + val.slice(endIndex);
|
||||
el.selectionStart = el.selectionEnd = endIndex + text.length;
|
||||
} else if (doc.selection != "undefined" && doc.selection.createRange) {
|
||||
el.focus();
|
||||
range = doc.selection.createRange();
|
||||
range.collapse(false);
|
||||
range.text = text;
|
||||
range.select();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue