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 10583 - [Selection] toString should return only the text within the selection that is visible to the user
Summary: [Selection] toString should return only the text within the selection that is...
Status: ASSIGNED
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: HISTORICAL - Selection API (show other bugs)
Version: unspecified
Hardware: Other other
: P3 normal
Target Milestone: ---
Assignee: Ryosuke Niwa
QA Contact: public-webapps-bugzilla
URL: https://w3c.github.io/selection-api/
Whiteboard:
Keywords:
: 10584 (view as bug list)
Depends on: 10798
Blocks:
  Show dependency treegraph
 
Reported: 2010-09-08 23:37 UTC by contributor
Modified: 2015-04-13 20:14 UTC (History)
11 users (show)

See Also:


Attachments

Description contributor 2010-09-08 23:37:40 UTC
Section: http://www.whatwg.org/specs/web-apps/current-work/#selection

Comment:
toString does not represent what WebKit and Mozilla do, which is to return
only the text within the selection that is visible to the user.

Posted from: 77.44.46.22
Comment 1 Tim Down 2010-09-09 08:13:20 UTC
*** Bug 10584 has been marked as a duplicate of this bug. ***
Comment 2 Tim Down 2010-09-09 09:05:38 UTC
I submitted this bug. Consider the following example HTML with 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 in both Mozilla and WebKit 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:

"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 section of the spec is too simplistic, since major browsers have historically done something more subtle (i.e. returning a concatenation of only the text that is visible to the user within each selection range).
Comment 3 Ian 'Hixie' Hickson 2010-09-26 17:12:57 UTC
It seems it's even more subtle than that... if I take your example but make the script element display:block, I get the script's contents with newlines around it in the .toString() output.

I really don't want to make HTML depend on detailed CSS stuff for its definitions.

Anne, is there anything I can reference that can define this? Ms2ger, is there any chance you can take Selection wholesale and put it in DOM Range?
Comment 4 Anne 2010-09-26 17:19:38 UTC
It very much sounds like innerText. I am not sure where exactly that needs to be defined.
Comment 5 Aryeh Gregor 2011-02-01 19:00:44 UTC
I'm working on this, along with innerText (it will be the same algorithm for both).
Comment 6 Aryeh Gregor 2011-09-22 19:31:10 UTC
Moving Selection-related bugs to editing: see bug 14248, bug 14252.
Comment 7 Ben Peters 2014-04-21 21:10:10 UTC
Moving to Selection API component.