<?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>145212</bug_id>
          
          <creation_ts>2015-05-20 10:41:44 -0700</creation_ts>
          <short_desc>selection.getRangeAt(0) should return a reference to the range, not a copy</short_desc>
          <delta_ts>2023-02-06 13:11:58 -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>DOM</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>216325</dup_id>
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=216325</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>BrowserCompat, InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Michał Gołębiowski-Owczarek">m.goleb+bugzilla</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ahmad.saleem792</cc>
    
    <cc>ap</cc>
    
    <cc>cdumez</cc>
    
    <cc>clopez</cc>
    
    <cc>db</cc>
    
    <cc>enrica</cc>
    
    <cc>karlcow</cc>
    
    <cc>megan_gardner</cc>
    
    <cc>rniwa</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>wenson_hsieh</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1096284</commentid>
    <comment_count>0</comment_count>
    <who name="Michał Gołębiowski-Owczarek">m.goleb+bugzilla</who>
    <bug_when>2015-05-20 10:41:44 -0700</bug_when>
    <thetext>Steps to reproduce the problem:
1. Select some text on any page.
2. Open DevTools, go to the console
3. Enter:

var selection = getSelection();
selection.getRangeAt(0) === selection.getRangeAt(0);

It returns false. The spec:
https://dvcs.w3.org/hg/editing/raw-file/tip/editing.html#dom-selection-getrangeat
is clear:
&quot;it must return a reference to (not a copy of) the context object&apos;s range.&quot;

The same happens in Chrome; Firefox does the right thing.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1096298</commentid>
    <comment_count>1</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2015-05-20 11:17:58 -0700</bug_when>
    <thetext>Range support is quite limited in WebKit in a lot of ways, I&apos;m not sure if we&apos;ll ever try to fix this particular aspect.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1128230</commentid>
    <comment_count>2</comment_count>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2015-09-22 23:04:28 -0700</bug_when>
    <thetext>Ryosuke, what do you think about this? I see that you are the spec editor :)

FYI, this is causing many failures in the following W3C DOM test:
imported/w3c/web-platform-tests/dom/ranges/Range-mutations.html</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1128231</commentid>
    <comment_count>3</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2015-09-22 23:05:45 -0700</bug_when>
    <thetext>&lt;rdar://problem/22815169&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1527716</commentid>
    <comment_count>4</comment_count>
    <who name="Danilo">db</who>
    <bug_when>2019-04-16 06:02:23 -0700</bug_when>
    <thetext>I came across this problem when implementing a text editor. The spec clearly says that a reference should be returned, not a copy, so Safari does not implement getRangeAt in a compliant way.

A workaround is to modify the returned range, to remove the existing selection ranges and to re-add the modified range to the DOM. But that&apos;s quite an inefficient way of working with selections and ranges.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1527717</commentid>
    <comment_count>5</comment_count>
    <who name="Danilo">db</who>
    <bug_when>2019-04-16 06:03:28 -0700</bug_when>
    <thetext>By the way, here is the current version of the spec: https://w3c.github.io/selection-api/#dom-selection-getrangeat</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1527720</commentid>
    <comment_count>6</comment_count>
    <who name="Michał Gołębiowski-Owczarek">m.goleb+bugzilla</who>
    <bug_when>2019-04-16 06:05:45 -0700</bug_when>
    <thetext>Chrome used to have the same issue but it no longer does. Chrome 73 passes the test case from the initial post.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1527721</commentid>
    <comment_count>7</comment_count>
      <attachid>367531</attachid>
    <who name="Danilo">db</who>
    <bug_when>2019-04-16 06:12:11 -0700</bug_when>
    <thetext>Created attachment 367531
Testcase to reproduce the issue</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1528004</commentid>
    <comment_count>8</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2019-04-16 21:13:16 -0700</bug_when>
    <thetext>*** Bug 160676 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1619922</commentid>
    <comment_count>9</comment_count>
    <who name="Carlos Alberto Lopez Perez">clopez</who>
    <bug_when>2020-02-17 15:06:58 -0800</bug_when>
    <thetext>I was checking the many failures of WebKit on the WPT &quot;selection/&quot; tests and it seems most of them are related with this bug.

https://wpt.fyi/results/selection?label=master&amp;product=chrome%5Bexperimental%5D&amp;product=firefox%5Bexperimental%5D&amp;product=safari%5Bexperimental%5D&amp;product=webkitgtk&amp;aligned&amp;q=%28safari%3A%21pass%26safari%3A%21ok%29%20%28chrome%3Apass%7Cchrome%3Aok%29%20%28firefox%3Apass%7Cfirefox%3Aok%29

&quot;selection.addRange(foo)&quot; on WebKit doesn&apos;t set the selection range by a reference to &quot;foo&quot; (against the spec). So then the tests fail to assert that the range of the selection its the same range object added with addRange(), or that it has the expected properties. Example: http://wpt.live/selection/addRange.htm</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1619924</commentid>
    <comment_count>10</comment_count>
    <who name="Carlos Alberto Lopez Perez">clopez</who>
    <bug_when>2020-02-17 15:10:26 -0800</bug_when>
    <thetext>*** Bug 15921 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1620539</commentid>
    <comment_count>11</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2020-02-18 21:43:58 -0800</bug_when>
    <thetext>Indeed! This will fix many WPT failures. However, this will require a massive engineering effort, and at the end of the day, it&apos;s probably not the most important compatibility bug since virtually all rich text editor in production works around this behavior difference already.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1691794</commentid>
    <comment_count>12</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2020-09-24 23:33:46 -0700</bug_when>
    <thetext>Looks like Darin is going to fix this in https://bugs.webkit.org/show_bug.cgi?id=216325</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1931467</commentid>
    <comment_count>13</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2023-02-06 13:04:27 -0800</bug_when>
    <thetext>Attached testcase seems to work fine now on WebKit ToT (259906@main) after Selection API - Live Ranges and update selection to move caret in between &apos;b&apos; and &apos;c&apos; as expected.

Can we close this as &quot;RESOLVED CONFIGURATION CHANGED&quot;? Thanks!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1931470</commentid>
    <comment_count>14</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2023-02-06 13:11:58 -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>367531</attachid>
            <date>2019-04-16 06:12:11 -0700</date>
            <delta_ts>2019-04-16 06:12:11 -0700</delta_ts>
            <desc>Testcase to reproduce the issue</desc>
            <filename>selection-testcase.html</filename>
            <type>text/html</type>
            <size>1303</size>
            <attacher name="Danilo">db</attacher>
            
              <data encoding="base64">PCFkb2N0eXBlIGh0bWw+CjxodG1sPgogICAgPGhlYWQ+CiAgICAgICAgPHRpdGxlPlNlbGVjdGlv
biBCdWc8L3RpdGxlPgogICAgICAgIDxzdHlsZSB0eXBlPSJ0ZXh0L2NzcyI+CiAgICAgICAgICAj
d3JhcHBlciB7IGJvcmRlcjogMXB4IHNvbGlkIGJsdWU7IH0KICAgICAgICA8L3N0eWxlPgogICAg
PC9oZWFkPgogICAgPGJvZHk+CiAgICAgICAgPGRpdiBpZD0id3JhcHBlciIgY29udGVudGVkaXRh
YmxlPmFiYzwvZGl2PgogICAgICAgIDxidXR0b24gaWQ9ImNyZWF0ZSI+Q3JlYXRlIHNlbGVjdGlv
bjwvYnV0dG9uPgogICAgICAgIDxidXR0b24gaWQ9InVwZGF0ZSI+VXBkYXRlIHNlbGVjdGlvbjwv
YnV0dG9uPgogICAgICAgIDxwPkNsaWNraW5nIHRoZSBmaXJzdCBidXR0b24gc2hvdWxkIGNyZWF0
ZSBhIHNlbGVjdGlvbiBiZXR3ZWVuIGEgYW5kIGIuCiAgICAgICAgQ2xpY2tpbmcgdGhlIHNlY29u
ZCBidXR0b24gc2hvdWxkIHVwZGF0ZSB0aGUgc2VsZWN0aW9uIGFuZCBtb3ZlIHRoZQogICAgICAg
IGNhcmV0IGJldHdlZW4gYiBhbmQgYy48L3A+CiAgICA8c2NyaXB0PgogICAgICAgIGNvbnN0IHdy
YXBwZXIgPSBkb2N1bWVudC5nZXRFbGVtZW50QnlJZCgid3JhcHBlciIpOwoKICAgICAgICBkb2N1
bWVudC5nZXRFbGVtZW50QnlJZCgiY3JlYXRlIikuYWRkRXZlbnRMaXN0ZW5lcigiY2xpY2siLCAo
ZSkgPT4gewogICAgICAgICAgY29uc3Qgc2VsID0gZG9jdW1lbnQuZ2V0U2VsZWN0aW9uKCk7CiAg
ICAgICAgICBjb25zdCByYW5nZSA9IGRvY3VtZW50LmNyZWF0ZVJhbmdlKCk7CiAgICAgICAgICBj
b25zdCB0ZXh0ID0gd3JhcHBlci5jaGlsZE5vZGVzWzBdOwogICAgICAgICAgcmFuZ2Uuc2V0U3Rh
cnQodGV4dCwgMSk7CiAgICAgICAgICByYW5nZS5jb2xsYXBzZSh0cnVlKTsKICAgICAgICAgIHNl
bC5yZW1vdmVBbGxSYW5nZXMoKTsKICAgICAgICAgIHNlbC5hZGRSYW5nZShyYW5nZSk7CiAgICAg
ICAgfSk7CgogICAgICAgIGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCJ1cGRhdGUiKS5hZGRFdmVu
dExpc3RlbmVyKCJjbGljayIsIChlKSA9PiB7CiAgICAgICAgICBjb25zdCBzZWwgPSBkb2N1bWVu
dC5nZXRTZWxlY3Rpb24oKTsKICAgICAgICAgIGNvbnN0IHJhbmdlID0gc2VsLmdldFJhbmdlQXQo
MCk7CiAgICAgICAgICBjb25zdCB0ZXh0ID0gd3JhcHBlci5jaGlsZE5vZGVzWzBdOwogICAgICAg
ICAgcmFuZ2Uuc2V0U3RhcnQodGV4dCwgMik7CiAgICAgICAgICByYW5nZS5jb2xsYXBzZSh0cnVl
KTsKICAgICAgICB9KTsKICAgIDwvc2NyaXB0PgogICAgPC9ib2R5Pgo8L2h0bWw+Cg==
</data>

          </attachment>
      

    </bug>

</bugzilla>