Thank you very much for the reply Joe! Sure, I've never heard of jsfiddle, but I could throw some code up there. Since I'll have to spend some time to figure it out and try and make this part of my application work with it, I'll do that in a bit. Maybe tomorrow since it's 11:45pm right now for me.
The IE problem is actually pretty simple to reason about though, at least if you've worked with TextRange objects and IE selections. 1) The first problem is that IE's TextRange object doesn't tell you *where* in a text node the cursor is at. So if you have span tag with the text "Hey Java Posse!", and the cursor is between 'Java' and 'Posse', IE we have no way to know that. With the W3C Range object, we could go "range.startOffset" or we could also ask the selection with "selection.anchorOffset". IE has no such functionality exposed to JavaScript. The best we can do is "range.parentElement()", which returns the container of the text node (Which would be the <span> DOM Element). This makes my algorithm not very cross-browser compatible because it relies on knowing the offset. Without it, the best we can do is getting the start position of every node... which is terrible. I wrote the algorithm assuming IE had some equivalent feature set even though their Range and Selection API is from a different planet. 2) The second problem is that there is no way to attach a newly create IE TextRange back to the DOM using script. With the W3C, we can attach a DOM node to the range, like this: range.setEnd( domElement, offset ); Unfortunately, IE did it backwards. You need to call createRange() as a method on an object. This would be fine if createRange() was exposed to all DOM elements within IE... but it isn't. Microsoft thought you should only create ranges on: document, body, input, and textarea DOM elements. So, if you wanted to get/set character positions on input and textareas... it's very, very easy. Unfortunately, using a basic textarea for this application is not possible. I need to use an editable div. Basically, IE makes doing really simple things much easier since you don't need to work with the DOM directly... but it makes really complex stuff EXTREMELY hard to do. Maybe what I'm trying to do is even impossible? There has been some efforts to emulate W3C Range/Selection APIs into Internet Explorer 6 through 8 (Microsoft refuses to implement it I guess....), but they are not 100% compatible. Actually, they are still quite bad for the kinds of things my application needs to do. On Apr 7, 10:44 pm, Joe Sondow <[email protected]> wrote: > So far this thread is an interesting day in the life of a smart > developer facing a tough problem and writing about it as he helps > himself through the problems one at a time. If the mystery remains, > can you post an example of what you have so far on jsfiddle.net so a > few of us can try to understand the IE problem? On Apr 7, 10:44 pm, Joe Sondow <[email protected]> wrote: > So far this thread is an interesting day in the life of a smart > developer facing a tough problem and writing about it as he helps > himself through the problems one at a time. If the mystery remains, > can you post an example of what you have so far on jsfiddle.net so a > few of us can try to understand the IE problem? -- You received this message because you are subscribed to the Google Groups "The Java Posse" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.
