JSFiddle - React, Tailwind, and code Playground
by Dave Salomon
HTML
<textarea rows="30" cols="80">
Here is some text in my editor.
When I double click at a position*
I want to inserted a new blank line above, at the same position
</textarea>
JavaScript
$('textarea').dblclick(function(e){
var text = this.value;
var newLinePos = text.lastIndexOf('\n', this.selectionStart);
var lineLength = this.selectionStart - newLinePos;
var newString = '\n';
for(var i=1; i < lineLength; ++i){
newString += ' ';
}
newString += text.substr(this.selectionStart,this.selectionEnd-this.selectionStart);
this.value = [text.slice(0, newLinePos), newString, text.slice(newLinePos)].join('');
});