Selection.toString behaviour does not conform to HTML5 draft

RESOLVED INVALID

Status

()

Core
Selection
--
enhancement
RESOLVED INVALID
8 years ago
6 years ago

People

(Reporter: Tim Down, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

8 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.9) Gecko/20100824 Firefox/3.6.9
Build Identifier: 

According to the selection section of the HTML5 draft

"Objects implementing this interface must stringify to a concatenation of the results of invoking the toString()  method of the Range object on each of the ranges of the selection, in the order they appear in the list (first to last)." 

This is not what happens in Mozilla (or WebKit, but is what happens in Opera), where Selection.toString() returns only the visible text within the selection (which seems like the correct behaviour to me). Consider the following piece of HTML (selection delimited by pipes):

<div>|One<script>var x = 1;</script>two|</div>

Calling toString() on a Range representing that selection would produce "Onevarx = 1;two", while calling toString() on the Selection object will produce "Onetwo". The latter behaviour is contrary to HTML5's specified behaviour, according to which it should return the same string as the Range.

I think Mozilla and WebKit have the correct behaviour here and would rather the HTML5 spec was altered.

Reproducible: Always
(Reporter)

Comment 2

8 years ago
I already have: http://www.w3.org/Bugs/Public/show_bug.cgi?id=10583. I posted the Mozilla bug to bring it to your attention, in case the HTML5 spec doesn't change.
The spec subsequently changed to not define Selection.toString() at all.  The current definition is a todo:

http://dvcs.w3.org/hg/editing/raw-file/9b1189899718/editing.html#dom-selection-stringifier

So this is invalid for now.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 6 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.