Caret position in textarea, in characters from the start explains how to figure out where the caret is when the user hits enter so that you can check whether there are three spaces and a line break to the left.
Enter key in textarea explains how to detect the Enter key in a textarea and take an action.
Once you have a listener hooked up and know the caret location is caret
, you can do something like
if (/(?:^|[\r\n]) (?:[^\r\n ][^\r\n]*)?$/
.test(myTextArea.value.substring(0, caret)) {
...
}
to take an action when there are exactly three spaces at the start of the current line.
To insert the 3 extra-spaces, you could do something like
myTextArea.value = myTextArea.value.substring(0, caret)
+ "\n " + myTextArea.value.substring(caret);