<?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>6350</bug_id>
          
          <creation_ts>2006-01-03 03:29:54 -0800</creation_ts>
          <short_desc>Selection shouldn&apos;t exclude collapsed whitespace</short_desc>
          <delta_ts>2023-02-25 07:37:06 -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>420+</version>
          <rep_platform>Mac</rep_platform>
          <op_sys>OS X 10.4</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>CONFIGURATION CHANGED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>HasReduction, InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          <dependson>23793</dependson>
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Alexey Proskuryakov">ap</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ahmad.saleem792</cc>
    
    <cc>bfulgham</cc>
    
    <cc>emacemac7</cc>
    
    <cc>eric</cc>
    
    <cc>evan</cc>
    
    <cc>ian</cc>
    
    <cc>michael.vm</cc>
    
    <cc>rniwa</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>27580</commentid>
    <comment_count>0</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2006-01-03 03:29:54 -0800</bug_when>
    <thetext>If a selection range set via setBaseAndExtent starts or ends with collapsed whitespace, it is excluded from 
the range, which doesn&apos;t happen in Firefox.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>27581</commentid>
    <comment_count>1</comment_count>
      <attachid>5446</attachid>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2006-01-03 03:30:34 -0800</bug_when>
    <thetext>Created attachment 5446
test case</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>27719</commentid>
    <comment_count>2</comment_count>
    <who name="Justin Garcia">justin.garcia</who>
    <bug_when>2006-01-04 01:23:55 -0800</bug_when>
    <thetext>Here&apos;s why this happens:

Positions passed to Selection::setBaseAndExtent are used to construct VisiblePositions.  VisiblePositions 
take the input position and find its canonical position: the position that is visually equivalent but &quot;deep&quot; 
and at a rendered offset (this canonical position is referred to internally as a &quot;deep equivalent&quot; and is 
returned by VisiblePosition::deepEquivalent())  For example:

&lt;div&gt;&lt;b&gt;hello   world&lt;/b&gt;&lt;/div&gt;

A VisiblePosition created with the Position (div, 0), would have a &quot;deep equivalent&quot; of (textnode, 0).
A VisiblePosition created with the Positions (textnode, 6), (textnode, 7), and (textnode, 8) would all 
have deep equivalents of (textnode, 8).

The behavior you see is caused because SelectionController takes the Positions passed to 
setBaseAndExxtent, creates VisiblePositions, then sets the base and the extent to the deep equivalents 
of those VisiblePositions.

SelectionController does even more fiddling with its positions.  When it creates start/end (from base/
extent), it upstream()s the end and downstream()s the start.  Comments in SelectionController claim 
that this is necessary to &quot;constrain&quot; the selection to the fewest possible nodes, in order to make it 
canonical for purposes of comparison with other selections.  I&apos;m not sure why this is necessary, since 
VisiblePosition&apos;s are already canonical.

Both of these things need to be addressed to fix this kind of bug (when ranges change when they are 
used to make selections).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>65615</commentid>
    <comment_count>3</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2007-12-29 11:17:38 -0800</bug_when>
    <thetext>See also: bug 15256.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1887868</commentid>
    <comment_count>4</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2022-07-30 10:25:51 -0700</bug_when>
    <thetext>I am able to reproduce this bug using attached test case in Safari 15.6 on macOS 12.5 and it shows offSet of 1 &amp; 7 rather than 0 and 8.

*** Safari 15.6 on macOS 12.5 ***

body.firstChild.nodeValue: \n123456\n
anchor: [object Text], offset: 1
focus: [object Text], offset: 7

*** Chrome Canary 106 ***

body.firstChild.nodeValue: \n123456\n
anchor: [object Text], offset: 0
focus: [object Text], offset: 8

*** Firefox Nightly 105 ***

body.firstChild.nodeValue: \n123456\n
anchor: [object Text], offset: 0
focus: [object Text], offset: 8

________

I am not sure on web-spec but just wanted to share latest test results. Thanks!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1887871</commentid>
    <comment_count>5</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2022-07-30 10:41:38 -0700</bug_when>
    <thetext>&lt;rdar://problem/97840483&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1936751</commentid>
    <comment_count>6</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2023-02-25 07:37:06 -0800</bug_when>
    <thetext>Fixed by Live Range Selection API. Confirmed on Safari Technology Preview 164.

Marking this as &quot;RESOLVED CONFIGURATION CHANGED&quot;. Thanks!</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>5446</attachid>
            <date>2006-01-03 03:30:34 -0800</date>
            <delta_ts>2006-01-03 03:30:34 -0800</delta_ts>
            <desc>test case</desc>
            <filename>collapsed-newline.html</filename>
            <type>text/html</type>
            <size>1544</size>
            <attacher name="Alexey Proskuryakov">ap</attacher>
            
              <data encoding="base64">PGh0bWw+CjxoZWFkPgo8c3R5bGU+CmJvZHkgeyBtYXJnaW46IDEwOyBwYWRkaW5nOiAwIH0KPC9z
dHlsZT4KPC9oZWFkPgo8Ym9keSA+CjEyMzQ1Ngo8c2NyaXB0IHR5cGU9InRleHQvamF2YXNjcmlw
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VBbmRFeHRlbnQocmFuZ2Uuc3RhcnRDb250YWluZXIsIHJhbmdl
LnN0YXJ0T2Zmc2V0LCByYW5nZS5lbmRDb250YWluZXIsIHJhbmdlLmVuZE9mZnNldCk7CiAgICAg
ICAgfQoKICAgICAgICBsb2coImFuY2hvcjogIiArIHdpbmRvdy5nZXRTZWxlY3Rpb24oKS5hbmNo
b3JOb2RlICsgIiwgb2Zmc2V0OiAiICsgd2luZG93LmdldFNlbGVjdGlvbigpLmFuY2hvck9mZnNl
dCk7CiAgICAgICAgbG9nKCJmb2N1czogIiArIHdpbmRvdy5nZXRTZWxlY3Rpb24oKS5mb2N1c05v
ZGUgKyAiLCBvZmZzZXQ6ICIgKyB3aW5kb3cuZ2V0U2VsZWN0aW9uKCkuZm9jdXNPZmZzZXQpOwog
ICAgICAgIGxvZygiKG9mZnNldHMgc2hvdWxkIGJlIDAgYW5kIDgsIHJlc3BlY3RpdmVseSkiKTsK
CiAgICB9IGNhdGNoIChleCkgewogICAgICAgIGxvZygiRXhjZXB0aW9uOiAiICsgZXguZGVzY3Jp
cHRpb24pOwogICAgfQogICAgCiAgICB2YXIgY29uc29sZSA9IGRvY3VtZW50LmNyZWF0ZUVsZW1l
bnQoInAiKTsKICAgIGNvbnNvbGUuYXBwZW5kQ2hpbGQoY29uc29sZV9tZXNzYWdlcyk7CiAgICBk
b2N1bWVudC5ib2R5LmFwcGVuZENoaWxkKGNvbnNvbGUpOwoKPC9zY3JpcHQ+CjwvYm9keT4KPC9o
dG1sPgo=
</data>

          </attachment>
      

    </bug>

</bugzilla>