add tab support for textareas
This commit is contained in:
parent
488a515a24
commit
f2eb16c574
1 changed files with 33 additions and 14 deletions
|
@ -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;
|
||||
}
|
||||
}))
|
||||
|
||||
|
|
Loading…
Reference in a new issue