<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>15470</bug_id>
          
          <creation_ts>2012-01-09 14:59:07 +0000</creation_ts>
          <short_desc>Changing the selection creates a Range object</short_desc>
          <delta_ts>2014-09-16 01:20:54 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebAppsWG</product>
          <component>HISTORICAL - Selection API</component>
          <version>unspecified</version>
          <rep_platform>PC</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>REOPENED</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Anne">annevk</reporter>
          <assigned_to name="Ryosuke Niwa">rniwa</assigned_to>
          <cc>benjamp</cc>
    
    <cc>mike</cc>
    
    <cc>public-webapps</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>62412</commentid>
    <comment_count>0</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2012-01-09 14:59:07 +0000</bug_when>
    <thetext>Make it explicit that once the user changes the selection a Range object is created and associated with the selection.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>62518</commentid>
    <comment_count>1</comment_count>
    <who name="Aryeh Gregor">ayg</who>
    <bug_when>2012-01-10 21:15:47 +0000</bug_when>
    <thetext>Browsers seem to differ here.  Tested: IE9, Firefox 12.0a1, Chrome 17 dev, Opera Next 12.00 alpha.

Initial range: In IE, Chrome, and Opera, getSelection().rangeCount is initially 0.  In Firefox, it&apos;s initially 1, with the range collapsed at (document, 0) like with all new ranges.

When the user changes the selection: All browsers replace the existing range with a new one (they don&apos;t mutate the old one).

When the user clicks somewhere without dragging, so the selection/cursor disappear: Opera sets rangeCount to 0.  Firefox and Chrome make the selection&apos;s range collapse at the indicated place.  IE make the range collapse to the indicated place if you actually click on some text, but sets rangeCount back to 0 if you click on empty space.


Conclusion: Firefox&apos;s behavior is simplest, because it means that if no one calls removeRange/removeAllRanges, rangeCount is always 1, and getRangeAt(0) never throws.

I wonder if we could get away with making removeRange/removeAllRanges actually reset the range to (document, 0)?  Or maybe even (document.documentElement, 0)?  That would be a significant additional simplification for authors -- then rangeCount is *always* 1.  remove(All)Range(s) followed by addRange would still work as expected.  Hmm . . .

More complicated than I expected!  (Which just shows that I&apos;m unreasonably optimistic, I guess.)  I&apos;ll send out a mail and update the spec tomorrow.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>62552</commentid>
    <comment_count>2</comment_count>
    <who name="Aryeh Gregor">ayg</who>
    <bug_when>2012-01-11 17:12:49 +0000</bug_when>
    <thetext>I clarified behavior requirements for how to associate ranges with selections, matching Firefox as noted in comment 1: http://dvcs.w3.org/hg/editing/rev/c989dd9e441d

Started a discussion for possible further change: http://lists.w3.org/Archives/Public/public-webapps/2012JanMar/0107.html</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>62570</commentid>
    <comment_count>3</comment_count>
    <who name="Aryeh Gregor">ayg</who>
    <bug_when>2012-01-11 19:35:25 +0000</bug_when>
    <thetext>(In reply to comment #1)
&gt; Initial range: In IE, Chrome, and Opera, getSelection().rangeCount is initially
&gt; 0.  In Firefox, it&apos;s initially 1, with the range collapsed at (document, 0)
&gt; like with all new ranges.

This turned out to be wrong.  Actually, all browsers start rangeCount as 0.  However, I was testing in Live DOM Viewer, and the range wasn&apos;t removed when the iframe got unloaded.  IE9 and Opera Next 12.00 alpha do appear to remove the range on unload, which is what I&apos;d expect; Firefox 12.0a1 and Chrome 17 dev do not.  I fixed the spec so the range is initially null (matching all browsers), and specified the IE/Opera behavior for unload (with a test):

http://dvcs.w3.org/hg/editing/rev/6aaa4b8455c9</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>104121</commentid>
    <comment_count>4</comment_count>
    <who name="Ben Peters">benjamp</who>
    <bug_when>2014-04-21 21:07:29 +0000</bug_when>
    <thetext>Moving to Selection API component.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>111570</commentid>
    <comment_count>5</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2014-09-16 01:20:54 +0000</bug_when>
    <thetext>Reopening the bug per https://bugzilla.mozilla.org/show_bug.cgi?id=671152</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>