I’ve been really busy at work, so I originally missed seeing that a getSelection patch (bug 88049) had finally been checked into the latest nightlies. I’ve been waiting for this for over 2 years now, ever since I tried to implement the Blogger text-edit controls in an early milestone build of Mozilla (haha, I tried using window.getSelection(), silly me, why would I ever think that would return a selection?).
Now, here was where I was going to announce my triumphant victory. After all, it’s relatively simple to code, assuming the feature is working. And to that end, I’ve spent a few hours over the past few days whipping it up. But that little matter about the feature actually working? Well, it doesn’t really. With the current nightly builds, the ranging features die horribly when hard line-breaks are involved. Apparently, in those cases, the text nodes are represented in separate text nodes internally (this is not accessible to us mere mortal webmonkey’s, however. the DOM Inspector shows the entire text as one single textarea – I even tried to work around it by working on counts from the textLength, but it’s a no-go, the problem is intractable on this end). Also, even when it does work, there doesn’t seem to be any way to undo once you’ve done the insert. That’s awfully annoying. The entire selection / input / editing functionality in Mozilla seems to be pretty rickety, especially when compared to how well IE’s text editing. (Should I even mention ContentEditable? Well, at least there’s Xopus for that – no hope for an XBL fix for selections, that’s still broken.)
Umm, hmm, I’m ranting again. Anyway, as the bug is being actively patched, maybe in a few days this will actually work properly. Until then, it still will, but only if there are no hard line breaks:
I made versions for metafilter and blogger as well. Along the way, I found a fix for blogger’s wonky textare display. It renders properly when the following style code is added:
form { height:100%; padding:0; margin:0; }
I submitted that tidbit to Shellen the other night, but haven’t seen the change go up yet.
Ending massive post by clearing out some random links:
- Using the W3C DOM Level 2 Range Object as Implemented by Mozilla – old and posted before, but it’s a good article
- Mozilla Editor – Tony Gorman wrote a proof of concept, primarily to test caret position values.
- Text Input Selection Test
- Another one