add tab support for textareas

This commit is contained in:
Inhji 2023-06-04 21:05:38 +02:00
parent 488a515a24
commit f2eb16c574

View file

@ -64,3 +64,22 @@ document
window.localStorage.setItem("theme", "dark")
}
})
document
.querySelectorAll('textarea')
.forEach(e => e.addEventListener('keydown', function(e) {
if (e.key == 'Tab') {
e.preventDefault();
var start = this.selectionStart;
var end = this.selectionEnd;
// set textarea value to: text before caret + tab + text after caret
this.value = this.value.substring(0, start) +
"\t" + this.value.substring(end);
// put caret at right position again
this.selectionStart =
this.selectionEnd = start + 1;
}
}))