[whatwg] HTML5 7.6.1 Selection problems

I am concerned about some aspects of section 7.6.1 in the HTML5
specification, relating to Selection objects. My main concern is that
some parts do not match current browser behaviour, in particular
relating to "backwards" selections (i.e. where the focus point comes
before the anchor point within the document).

Current browsers, unlike the HTML5 spec, allow both detection and
creation of backwards selections. Detection is via the anchorNode,
anchorOffset, focusNode and focusOffset properties. The selection
focus may be at a point in the document prior to the selection anchor,
meaning that the selection is backwards. In the HTML5 spec, the
selection focus must always be the same or after the anchor in the
document (http://www.w3.org/Bugs/Public/show_bug.cgi?id=10624).
Creation is via the expand method: it's possible to create a Range and
add it to the selection (making the selection anchor equal to the
start of the Range) and use the expand() method to move the selection
focus to any point in the document, including a point before the
selection anchor. HTML5 does not specify the expand() method
(http://www.w3.org/Bugs/Public/show_bug.cgi?id=10691). It seems to me
that it's important to be able create and manipulate backwards
selections: browsers already do it and it's useful within the context
of an editable element or document.

An unrelated issue is in the toString() method of Selection objects.
In HTML5, this takes a simplistic approach of concatenating the
results of calling toString() on each Range within the selection. This
is unfortunately not how any browser implements it or ever has:
toString() in Mozilla, WebKit and Opera returns only the text within
the selection that is visible to the user, omitting, for example, text
nodes within elements hidden by CSS properties such as display and
text nodes within <script> elements
(http://www.w3.org/Bugs/Public/show_bug.cgi?id=10583). The behaviour
is somewhat similar to that of an element's innerText property as
implemented in IE or WebKit.

In summary, the changes I'd like to see in section 7.6.1 of the HTML5 spec:

1. Change the specification of anchorNode, anchorOffset, focusNode and
focusOffset to be dependent on the direction of the selection but
still match either the start or end of the last range in the
selection;

2. Add the expand() method of Selection objects, matching current
browser behaviour;

3. Change the specification of the toString() method of Selection
objects to match current browser behaviour.


Tim Down

Received on Wednesday, 22 September 2010 17:21:05 UTC