I'm currently working on a text editor embedded within a contenteditable div.
My goal is to modify the [TAB] functionality so that instead of shifting focus to the next element (as is done by default in browsers), it will either insert spaces or a \t character in the text area.
To achieve this, I've implemented an event handler as follows:
function keyDown(e) {
// Capture tab press.
if (e.keyCode == 9) {
e.preventDefault();
return;
}
}
With this code in place, focus is maintained on the div. Now I just need to figure out how to actually insert a [TAB] or spaces at the current cursor position.
Any suggestions on how to accomplish this?