We all know the little toolbar buttons to insert something into a textarea, like BBCode, Wiki markup or HTML tags (fun fact: GitHub doesn't have a toolbar). One of the resources I used once was this German site but there are many more. I was wondering, how much of this nifty, widespread code could be squished into 140 bytes.
Currently, this is 158 154 bytes and I'm looking for your help. One thing I could do is to remove a.focus();
and +b.length
but doing so I will loose a major feature. I'm looking for other ways to make this smaller.
I also tried to use a regular expression but it's, well, complicated. Here is the shortest solution I found so far:
a.value=a.value.replace(RegExp('([\\s\\S]{'+a[d]+'})([\\s\\S]{'+(f-a[d])+'})'),'$1'+b+'$2'+c);
. The most reliable solution is this, but it's 3 bytes longer than using split:g=a.value;a.value=g.slice(0,a[d])+b+g.slice(a[d],f)+c+g.slice(f);
.