Skip to content Skip to sidebar Skip to footer

Why Does This Textarea Appear To Only Add One Space Instead Of Four?

Here is my code: doc.on('keydown', '.textarea_code_snippet', function(e) { if(e.keyCode === 9) { // tab was pressed // get caret position/selection var start =

Solution 1:

It does add four spaces. You just forgot to adjust one thing:

// put caret at right position again (add one for the tab)this.selectionStart = this.selectionEnd = start + 1;

You probably see the caret move by only one space. You need to change the above lines to:

// Put caret at right position again (add four for four spaces)this.selectionStart = this.selectionEnd = start + 4;

Post a Comment for "Why Does This Textarea Appear To Only Add One Space Instead Of Four?"