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

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>23600</bug_id>
          
          <creation_ts>2009-01-28 13:49:50 -0800</creation_ts>
          <short_desc>Selection.collapse does not work as expected on empty text nodes</short_desc>
          <delta_ts>2022-12-17 22:05:29 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>HTML Editing</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Mac</rep_platform>
          <op_sys>OS X 10.5</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>216325</dup_id>
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          <dependson>15256</dependson>
    
    <dependson>23601</dependson>
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Eric Seidel (no email)">eric</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ahmad.saleem792</cc>
    
    <cc>ap</cc>
    
    <cc>darin</cc>
    
    <cc>jparent</cc>
    
    <cc>justin.garcia</cc>
    
    <cc>ojan</cc>
    
    <cc>rniwa</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>107389</commentid>
    <comment_count>0</comment_count>
    <who name="Eric Seidel (no email)">eric</who>
    <bug_when>2009-01-28 13:49:50 -0800</bug_when>
    <thetext>Ojan and I were trying to use comparePoint in a test case.  It didn&apos;t work like we thought it would.  After some investigation, it just seems our ranges are borked.  This is probably a dupe of the &quot;VisualPosiition shouldn&apos;t be used as much as they are&quot; bug.

Test case:
&lt;html&gt;
&lt;body&gt;
    &lt;div id=&apos;log&apos;&gt;&lt;/div&gt;
&lt;script&gt;
function debug(str) {
    var logger = document.getElementById(&apos;log&apos;);
    logger.appendChild(document.createTextNode(str));
    logger.appendChild(document.createElement(&apos;br&apos;));
}
var div = document.createElement(&apos;div&apos;);
document.body.appendChild(div);
var textNode = document.createTextNode(&quot;&quot;);
div.appendChild(textNode);

var sel = window.getSelection();
sel.collapse(textNode, 0);
var range = sel.getRangeAt(0);

debug(&quot;comparing point with &lt;text&gt;, offset 0:&quot;);
var result = range.comparePoint(textNode, 0);
if (result == 0) {
    debug(&quot;PASSED: result = 0&quot;);
} else {
    debug(&quot;FAILED: result = &quot; + result + &quot; expected 0&quot;);
}

debug(&quot;range:&quot;);
debug(&quot;startContainer: &quot; + range.startContainer);
debug(&quot;startOffset: &quot; + range.startOffset);
debug(&quot;endContainer: &quot; + range.endContainer);
debug(&quot;endOffset: &quot; + range.endOffset);

debug(&quot;selection:&quot;);
debug(&quot;anchorNode: &quot; + sel.anchorNode);
debug(&quot;anchorOffset: &quot; + sel.anchorOffset);
debug(&quot;focusNode: &quot; + sel.focusNode);
debug(&quot;focusOffset: &quot; + sel.focusOffset);
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>107390</commentid>
    <comment_count>1</comment_count>
      <attachid>27121</attachid>
    <who name="Eric Seidel (no email)">eric</who>
    <bug_when>2009-01-28 13:50:08 -0800</bug_when>
    <thetext>Created attachment 27121
test case</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>107391</commentid>
    <comment_count>2</comment_count>
    <who name="Eric Seidel (no email)">eric</who>
    <bug_when>2009-01-28 13:54:29 -0800</bug_when>
    <thetext>Ok, turns out there are at least two bugs at play.  Repurposing this one to cover &quot;Range.collapse does not work as expected on empty text nodes&quot;, and will file a separate bug with slightly modified test case showing more clearly that getRangeAt(0) is mutating the Range in a bad bad way.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>107418</commentid>
    <comment_count>3</comment_count>
    <who name="Justin Garcia">justin.garcia</who>
    <bug_when>2009-01-28 15:16:13 -0800</bug_when>
    <thetext>(In reply to comment #2)
&gt; Ok, turns out there are at least two bugs at play.  Repurposing this one to
&gt; cover &quot;Range.collapse does not work as expected on empty text nodes

Looks like you&apos;re using Selection.collapse not Range.collapse.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>113960</commentid>
    <comment_count>4</comment_count>
    <who name="Eric Seidel (no email)">eric</who>
    <bug_when>2009-03-16 17:44:58 -0700</bug_when>
    <thetext>I think this in the end is just another dupe of bug 15256.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1920110</commentid>
    <comment_count>5</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2022-12-16 16:14:26 -0800</bug_when>
    <thetext>Using attached test case:

*** Safari Technology Preview 160 ***

comparing point with &lt;text&gt;, offset 0:
FAILED: result = 1 expected 0
range:
startContainer: [object HTMLBodyElement]
startOffset: 0
endContainer: [object HTMLBodyElement]
endOffset: 0
selection:
anchorNode: [object HTMLBodyElement]
anchorOffset: 0
focusNode: [object HTMLBodyElement]
focusOffset: 0

*** Chrome Canary 110 &amp; Firefox Nightly 110 ***

comparing point with &lt;text&gt;, offset 0:
PASSED: result = 0
range:
startContainer: [object Text]
startOffset: 0
endContainer: [object Text]
endOffset: 0
selection:
anchorNode: [object Text]
anchorOffset: 0
focusNode: [object Text]
focusOffset: 0

____

Just wanted to share updated test result. Thanks!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1920309</commentid>
    <comment_count>6</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2022-12-17 19:20:58 -0800</bug_when>
    <thetext>Probably fixed by the live range selection work that Ryosuke is doing.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1920320</commentid>
    <comment_count>7</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2022-12-17 22:05:15 -0800</bug_when>
    <thetext>Indeed, this test case passes once live range selection is enabled.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1920321</commentid>
    <comment_count>8</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2022-12-17 22:05:29 -0800</bug_when>
    <thetext>

*** This bug has been marked as a duplicate of bug 216325 ***</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>27121</attachid>
            <date>2009-01-28 13:50:08 -0800</date>
            <delta_ts>2009-01-28 13:50:08 -0800</delta_ts>
            <desc>test case</desc>
            <filename>testrange.html</filename>
            <type>text/html</type>
            <size>1090</size>
            <attacher name="Eric Seidel (no email)">eric</attacher>
            
              <data encoding="base64">PGh0bWw+Cjxib2R5PgogICAgPGRpdiBpZD0nbG9nJz48L2Rpdj4KPHNjcmlwdD4KZnVuY3Rpb24g
ZGVidWcoc3RyKSB7CiAgICB2YXIgbG9nZ2VyID0gZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoJ2xv
ZycpOwogICAgbG9nZ2VyLmFwcGVuZENoaWxkKGRvY3VtZW50LmNyZWF0ZVRleHROb2RlKHN0cikp
OwogICAgbG9nZ2VyLmFwcGVuZENoaWxkKGRvY3VtZW50LmNyZWF0ZUVsZW1lbnQoJ2JyJykpOwp9
CnZhciBkaXYgPSBkb2N1bWVudC5jcmVhdGVFbGVtZW50KCdkaXYnKTsKZG9jdW1lbnQuYm9keS5h
cHBlbmRDaGlsZChkaXYpOwp2YXIgdGV4dE5vZGUgPSBkb2N1bWVudC5jcmVhdGVUZXh0Tm9kZSgi
Iik7CmRpdi5hcHBlbmRDaGlsZCh0ZXh0Tm9kZSk7Cgp2YXIgc2VsID0gd2luZG93LmdldFNlbGVj
dGlvbigpOwpzZWwuY29sbGFwc2UodGV4dE5vZGUsIDApOwp2YXIgcmFuZ2UgPSBzZWwuZ2V0UmFu
Z2VBdCgwKTsKCmRlY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