ro31337 / jquery.ns-autogrow

Automatically adjust textarea width/height based on user input. Non-sucking version.
http://bit.ly/1NeshO8
166 stars 49 forks source link

tabs are ignored #21

Open Disc0Smurf opened 6 years ago

Disc0Smurf commented 6 years ago

I'm not an expert on this kind of stuff, so it could be I missed it, but the 'full sized' js file (not the .min.js file) doesn't take tabs into a count. I had a big html file open and noticed the width didn't match and that's when I found out that the shadow element doesn't have the tabs from the original textarea value. For it worked when I added .replace(/\t/g,' ') on the update function after the val = _this.value.replace(..... This is not the cleanest way to fix it though.

Disc0Smurf commented 6 years ago

I just realised this doesn't actually add tabs to the val variable, it just adds the text  ...

ro31337 commented 6 years ago

can you add steps to reproduce/demo?

Disc0Smurf commented 6 years ago

I put together a small fiddle

ro31337 commented 6 years ago

Makes sense. I think it's better to replace with     . Width of four can be little bit different from width of \t. Non-breaking spaces should work OK. Can you introduce PR for this fix? (src directory only is ok).

Just make sure it works, and I'll compile and publish it everywhere.

Thanks!

Disc0Smurf commented 6 years ago

Geez man, I don't know how that'll work. In my case, I'm using a monospace font and tab-size as number (of chars). So I just wrote a function: var tab = ""; for(i=0;i<parseInt($el.css("tab-size"));i++) tab+="X"; value=value.replace(/\t/g,tab); I honestly have no idea how to make this compatible with other ways of tab-size. No offense but I'm not really looking for a PR. If you do however find a fix, please let me know! And best of luck!