W3C home > Mailing lists > Public > whatwg@whatwg.org > June 2011

[whatwg] Generalized execCommand() alternatives, or standardized selection and range handling

From: Tim Down <timdown@gmail.com>
Date: Fri, 3 Jun 2011 01:07:58 +0100
Message-ID: <BANLkTimTYgH_zrxrWGueoqK3jshbL_6N9w@mail.gmail.com>
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
Received on Thursday, 2 June 2011 17:07:58 UTC

This archive was generated by hypermail 2.3.1 : Monday, 13 April 2015 23:09:06 UTC