W3C home > Mailing lists > Public > public-webapps@w3.org > July to September 2014

Re: [selection] Selection.setBaseAndExtent

From: Tim Down <tim@timdown.co.uk>
Date: Wed, 6 Aug 2014 10:40:31 +0100
Message-ID: <CAOYSAj2NFs5q+GHyQW1D5+ws3cLeCvZe6UzhuJtru6HsjHVqQQ@mail.gmail.com>
To: Ben Peters <Ben.Peters@microsoft.com>
Cc: Ryosuke Niwa <rniwa@apple.com>, "public-webapps@w3.org" <public-webapps@w3.org>
This doesn't fully cover what setBaseAndExtent() does in WebKit/Blink: as
you pointed out yourself, it acts like extend(), which allows programmatic
creation of backwards selection by providing a focus (extent) that is
earlier in the document than the anchor (base). Your text doesn't cover the
backwards case.

Borrowing from the spec text for extend() and minus all the links to
definitions, how about:

void setBaseAndExtent (Node baseNode, unsigned long baseOffset, Node
extentNode, unsigned long extentOffset);

The setBaseAndExtent(baseNode, baseOffset, extentNode, extentOffset) method
must run these steps:

1. Let base be the boundary point (baseNode, baseOffset) and extent be the
boundary point (extentNode, extentOffset).
2. Let new range be a new range.
3. If base is equal to extent, set new range's start and end to (baseNode,
baseOffset).
4. Otherwise, if base is before to extent, set new range's start to base,
then set its end to extent.
5. Otherwise, set new range's start to extent, then set its end to base.
6. Set the context object's range to new range.
7. If extent is before base, set the context object's direction to
backwards. Otherwise, set it to forwards.

Tim


On 5 August 2014 23:51, Ben Peters <Ben.Peters@microsoft.com> wrote:

>  I have added proposed text to this bug. Any objections to this?
>
>
>
> Proposed text, based on the text for collapse():
>
>
>
> void setBaseAndExtent (Node baseNode, unsigned long baseOffset, Node
> extentNode, unsigned long extentOffset);
>
>
>
> The method must throw an IndexSizeError exception if offset is negative or
> longer than node's length ([DOM4]). Otherwise, it must create a new range,
> set ([DOM4]) its start to (baseNode, baseOffset) and its and end to
> (extentNode, extentOffset), and set the context object's range to the
> newly-created range.
>
>
>
> *From:* Ben Peters
> *Sent:* Tuesday, May 20, 2014 11:37 AM
> *To:* Ben Peters; Ryosuke Niwa; public-webapps@w3.org
> *Subject:* RE: [selection] Selection.setBaseAndExtent
>
>
>
> I have filed a bug to track this issue [1].
>
>
>
> Ben
>
>
>
> [1] https://www.w3.org/Bugs/Public/show_bug.cgi?id=25831
>
>
>
>
>
> *From:* Ben Peters [mailto:Ben.Peters@microsoft.com
> <Ben.Peters@microsoft.com>]
> *Sent:* Monday, May 5, 2014 11:28 PM
> *To:* Ryosuke Niwa; public-webapps@w3.org
> *Subject:* [selection] Selection.setBaseAndExtent
>
>
>
> I noticed that some websites use selection.setBaseAndExtent [1]. According
> to what limited documentation I could find, it works similar to
> selection.extend. Is there any intention to standardize this, or is it made
> obsolete by selection.extend?
>
>
>
> Ben
>
>
>
> [1]
> http://stackoverflow.com/questions/985272/jquery-selecting-text-in-an-element-akin-to-highlighting-with-your-mouse
>
Received on Wednesday, 6 August 2014 09:40:59 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 18:14:26 UTC