[whatwg] Generalized execCommand() alternatives, or standardized selection and range handling
Tim Down
timdown at gmail.com
Thu Jun 2 17:07:58 PDT 2011
On 31 May 2011 18:39, Aryeh Gregor <Simetrical+w3c at gmail.com> wrote:
> On Tue, May 31, 2011 at 4:15 AM, Markus Ernst <derernst at gmx.ch> wrote:
>> Anyway, everything we need is actually available in the DOM, except a
>> standardized and simple handling of selections and ranges. (Well, I might be
>> wrong - but looking at the Gecko DOM reference and the MSDN DHTML reference,
>> they show very different approaches to the range and selection objects, and
>> the code of TinyMCE shows lots of browser sniffing.)
>
> That's because browsers' implementations don't follow the specs, or in
> some cases because there weren't specs until the last few months, not
> because there's anything wrong with the spec. I've implemented all my
> algorithms in pure JavaScript, and there are almost no places where I
> have to work around browser bugs -- given that I only target the
> latest versions of IE/Firefox/Chrome/Opera. implementation.js is over
> 4000 lines, and I estimate I've needed maybe ten browser-specific
> workarounds, certainly under twenty. (If you want to support IE<9, of
> course, have fun . . .)
I'm working on this. There was a perverse pleasure in getting to a
workable version of the Range and Selection APIs in IE < 9, and the
commands stuff I've recently built on top based on (a slightly
outdated version of) Aryeh's code has required relatively little
browser-specific code to get bold and italic working. Very rough demo
here (works in IE 6 - 8 as well as sensible browsers):
http://rangy.googlecode.com/svn/branches/1point2/demos/commands.html.
> The only major thing that can't be done in JS is change how ranges
> behave when you mutate the DOM. Effectively, I work around it by
> using a single Range object to represent the user's selection, and I
> only care how that changes. This might actually be the way I'll end
> up speccing it too, although it'd be nice if we could preserve ranges
> outside the selection too.
My version passes an array of ranges to be preserved to the command's
various internal methods. Works with multiple selected ranges in
Firefox.
Tim
More information about the whatwg
mailing list