<?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>20654</bug_id>
          
          <creation_ts>2013-01-12 09:57:52 +0000</creation_ts>
          <short_desc>Have Range.surroundContents() work for partially contained nodes?</short_desc>
          <delta_ts>2014-02-14 12:44:32 +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>DOM</component>
          <version>unspecified</version>
          <rep_platform>PC</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>WONTFIX</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="Anne">annevk</assigned_to>
          <cc>ayg</cc>
    
    <cc>mike</cc>
    
    <cc>www-dom</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>81300</commentid>
    <comment_count>0</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2013-01-12 09:57:52 +0000</bug_when>
    <thetext>&quot;Why does Range#surroundContents() throw if you split a non-text node? The logic is already there for extractContents(), so why not use it?&quot; https://twitter.com/yaypie/status/289891445672902657

&quot;It’s trivial to work around, but means that surroundContents() isn’t very useful as currently specced.&quot; https://twitter.com/yaypie/status/289891735394480128

The reason the specification suggests it is done (in a comment in the source) because it might be unexpected to clone containers.

Should we change this?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>81470</commentid>
    <comment_count>1</comment_count>
    <who name="Aryeh Gregor">ayg</who>
    <bug_when>2013-01-16 12:20:16 +0000</bug_when>
    <thetext>I don&apos;t think extractContents() does what we want here.  That clones *existing* containers.  In this case, I think expected behavior would be to clone the *new* container.  So if you have a DOM of
  &lt;p&gt;foo&lt;/p&gt;&lt;p&gt;bar&lt;/p&gt;
with &quot;ob&quot; selected, and do
  range.surroundContents(document.createElement(&quot;i&quot;))
I would expect
  &lt;p&gt;fo&lt;i&gt;o&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;b&lt;/i&gt;ar&lt;/p&gt;
not
  &lt;p&gt;fo&lt;i&gt;o&lt;p&gt;b&lt;/p&gt;&lt;/i&gt;&lt;/p&gt;&lt;p&gt;ar&lt;/p&gt;
which is what you&apos;d get if you applied extractContents().  The latter effect is much more disruptive, because you don&apos;t know what existing DOM structure you&apos;re messing with -- e.g., the misnesting here.  It&apos;s also equivalent to extractContents() + insertNode() + appendChild(), so no need for a separate function.  The former behavior is closer to what you&apos;d expect for a function that aims to do things like &quot;make selection bold&quot; in a simple-minded fashion, which I think is the goal of surroundContents().  The cloning shouldn&apos;t do anything surprising if you pass simple nodes to it -- e.g., just pass document.createElement() with some non-id attributes set and you&apos;re probably fine even if it gets cloned a bunch.

Even with the change, though, this method is too simplistic to use for even basic formatting.  If you have something like
  foo&lt;font color=red&gt;bar&lt;/font&gt;baz
and try to select all the text and wrap in &lt;font color=green&gt; using this method, it won&apos;t do what you want -- &quot;bar&quot; will remain red.  What&apos;s the use-case for using this method even with the change?  Does anyone use it now, and if so, for what?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>100430</commentid>
    <comment_count>2</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-02-12 19:53:20 +0000</bug_when>
    <thetext>Just to be clear, I am even less sure than Aryeh.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>