This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 26005 - Selection.extend behavior when there is no range needs to be clarified
Summary: Selection.extend behavior when there is no range needs to be clarified
Status: RESOLVED WORKSFORME
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: HISTORICAL - Selection API (show other bugs)
Version: unspecified
Hardware: PC Windows NT
: P2 normal
Target Milestone: ---
Assignee: Ryosuke Niwa
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-06-06 17:03 UTC by Ben Peters
Modified: 2014-09-16 01:18 UTC (History)
2 users (show)

See Also:


Attachments

Description Ben Peters 2014-06-06 17:03:00 UTC
Today, the Selection API spec seems to say that if selection.rangeCount is 0, then selection.extend should throw an error and abort. This is true in Firefox, but not Chrome. In Chrome, it appears that a new collapsed range is created at the position specified in selection.extend. Without an error, it's possible a site might end up creating a selection when they think they're extending it. But errors in JS should be used sparingly. Not sure which of these makes more sense.
Comment 1 Ben Peters 2014-08-05 22:49:18 UTC
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.
Comment 2 Ben Peters 2014-08-05 22:52:03 UTC
Ignore the last comment, Bugzilla was having login trouble that caused it to post to the wrong bug.
Comment 3 Ryosuke Niwa 2014-09-16 01:18:58 UTC
(In reply to Ben Peters from comment #0)
> Today, the Selection API spec seems to say that if selection.rangeCount is
> 0, then selection.extend should throw an error and abort. This is true in
> Firefox, but not Chrome. In Chrome, it appears that a new collapsed range is
> created at the position specified in selection.extend. Without an error,
> it's possible a site might end up creating a selection when they think
> they're extending it. But errors in JS should be used sparingly. Not sure
> which of these makes more sense.

This is taken care of by the first step in its definition:

"If the context object is empty, throw an InvalidStateError exception and abort these steps."

since the definition of "empty" is

"Each selection can be associated with a single range (defined in [DOM4]). When there is no range associated with the selection, the selection is empty. The selection must be initially empty."