jakiestfu / Behave.js

A lightweight, cross browser library for adding IDE style behaviors to plain text areas
http://jakiestfu.github.com/Behave.js/
1.74k stars 110 forks source link

Only one issue to resolve to add support for IE 7 and 8 #6

Closed jakiestfu closed 11 years ago

jakiestfu commented 11 years ago

Please read the article here: http://www.sitepoint.com/line-endings-in-javascript/

I cannot seem to get rid of the \r\n line ending in javascript.

The issue: On IE 7 and 8, a single newline has a length of 2 if within a textarea. Throws everything off.

SitePoint goes over a way around this but I cannot figure a way to implement this.

EDIT: More information

Setting the Caret position is OK, retrieving the actual value is wrong, see here:

http://jsfiddle.net/jakie8/xpD99/

bigspotteddog commented 11 years ago

I have setup a fiddle of the demo to start playing with this:

http://jsfiddle.net/F7FPG/

bigspotteddog commented 11 years ago

My bad. I assumed jsfiddle worked with IE8. I loaded the fiddle in VirtualBox (I'm on OSX) and discovered it does not. Sorry about that.

jakiestfu commented 11 years ago

No, it's all good.

Currently, I am thinking of an approach by measuring the newline characters length and then offsetting the carat get/sets by appropriate amounts, but it's still really tricky.

bigspotteddog commented 11 years ago

Cool and good luck. Nice work on this by-the-way. I love it.

Paratron commented 11 years ago

What exactly is your problem with the different line breaks?

jakiestfu commented 11 years ago

@Paratron The issue is IE 7/8 use \n\r as a line break instead of \n. So if you were to press enter on an empty textarea, you'd expect the values length to be one, but IE7/8 has a value of 2. This messes things up all around.

I was thinking about stripping the \r via the utils.editor.get method, but still, when I set everything, (data and carat), the carat is set in the wrong place.

birla commented 11 years ago

@jakiestfu I have a partially working fix in my fork, but utils.cursor.set is still causing issues. I have the tab and multiline tab working properly.

jakiestfu commented 11 years ago

@birla I see you're trying to fix the get caret issue.

I tried implementing it in a much simpler fashion, and it still did not work. Try messing with this fiddle and see if you can figure out how to fix this! Thanks for your help!

http://jsfiddle.net/jakie8/xpD99/

birla commented 11 years ago

@jakiestfu I took a shot at the fiddle and I was able to fix getting the caret position in all cases except when it's at the beginning of a new line.

http://jsfiddle.net/xpD99/1/

jakiestfu commented 11 years ago

@birla http://jsfiddle.net/jakie8/kreQP/5/

Type in a brace (which should give you an open and close), then keep pressing enter. For every time you press enter, the cursor's get position is incremented by one. I believe fixing that would also fix the issue with it at the newline. Any ideas? Thanks so much for your help!

jakiestfu commented 11 years ago

I have completed _full support_ for IE 7 and 8. Will push later tonight after cleaning it up a bit. Thanks for all of your help everyone!