<?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>27650</bug_id>
          
          <creation_ts>2014-12-18 05:55:06 +0000</creation_ts>
          <short_desc>Add range.insert(nodes...)</short_desc>
          <delta_ts>2016-08-19 12:23:06 +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>All</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="Glen Huang">hey.hgl</reporter>
          <assigned_to name="Anne">annevk</assigned_to>
          <cc>crimsteam</cc>
    
    <cc>joris</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>116457</commentid>
    <comment_count>0</comment_count>
    <who name="Glen Huang">hey.hgl</who>
    <bug_when>2014-12-18 05:55:06 +0000</bug_when>
    <thetext>Since DOM starts to allow multiple nodes to be manipulated in bulk (e.g., node.before, node.after), does it make sense to allow multiple nodes to be inserted into a range as well?
For example, range.insertNodes(nodes).

Also have a quick question on the algorithm of node.before and likes:

The before(nodes) method must run these steps:

1.If the context object does not have a parent, terminate these steps.
2.Run the mutation method macro.
3.Pre-insert node into the context object&apos;s parent before the context object.

Shouldn&apos;t step 3 be something like &quot;For each node in nodes ...&quot;, node was never defined in the algorithm. But maybe I missed something.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>116461</commentid>
    <comment_count>1</comment_count>
    <who name="Arkadiusz Michalski (Spirit)">crimsteam</who>
    <bug_when>2014-12-18 07:44:50 +0000</bug_when>
    <thetext>(In reply to Glen Huang from comment #0)
&gt; Since DOM starts to allow multiple nodes to be manipulated in bulk (e.g.,
&gt; node.before, node.after), does it make sense to allow multiple nodes to be
&gt; inserted into a range as well?
&gt; For example, range.insertNodes(nodes).

This can be done via range.insertNodes(documentFragment).

&gt; The before(nodes) method must run these steps:
&gt; 
&gt; 1.If the context object does not have a parent, terminate these steps.
&gt; 2.Run the mutation method macro.
&gt; 3.Pre-insert node into the context object&apos;s parent before the context object.
&gt; 
&gt; Shouldn&apos;t step 3 be something like &quot;For each node in nodes ...&quot;, node was
&gt; never defined in the algorithm. But maybe I missed something.

In step 2. we have &quot;mutation method macro&quot; which make DocumentFragment (when we have more than one node) or node, so this is correct.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>116462</commentid>
    <comment_count>2</comment_count>
    <who name="Glen Huang">hey.hgl</who>
    <bug_when>2014-12-18 07:53:48 +0000</bug_when>
    <thetext>Ah, that macro, I know I missed something. Thank you.

About inserting document fragment into the range, this is exactly what I&apos;m proposing. Instead of asking users to manually create it, DOM should take care of it, much like how it provides sugar like node.append, which is just document fragment + node.appendChild.

In this case, range.insertNodes is sugar for document fragment + range.insertNode.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>116463</commentid>
    <comment_count>3</comment_count>
    <who name="Arkadiusz Michalski (Spirit)">crimsteam</who>
    <bug_when>2014-12-18 08:09:52 +0000</bug_when>
    <thetext>Or extend insertNode() if it doesn&apos;t breake anything:

void insertNode((Node or DOMString)... nodes);

but the name of the method will be misleading.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>116464</commentid>
    <comment_count>4</comment_count>
    <who name="Glen Huang">hey.hgl</who>
    <bug_when>2014-12-18 08:16:24 +0000</bug_when>
    <thetext>Or just range.insert(nodes), like node.appendChild -&gt; node.append.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>122386</commentid>
    <comment_count>5</comment_count>
    <who name="Joris van der Wel">joris</who>
    <bug_when>2015-08-03 10:16:56 +0000</bug_when>
    <thetext>Why not make DocumentFragment easier to use instead?

For example: 

```
range.insertNode(new DocumentFragment(node1, &apos;a text node&apos;, node2));
range.insertNode(new DocumentFragment(document.getElementsByClassName(&apos;foo&apos;)));
range.insertNode([node1, node2]);
range.insertNode(new Set([node1, node2])); // iterable
```

This prevents having to change the spec in a lot of places.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>127146</commentid>
    <comment_count>6</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2016-08-17 12:05:10 +0000</bug_when>
    <thetext>Do you know if there&apos;s any implementer interest for these ideas? And precedence in JavaScript libraries? I&apos;m leaning towards closing this, but you can always open a new issue on GitHub.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>127175</commentid>
    <comment_count>7</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2016-08-19 12:23:06 +0000</bug_when>
    <thetext>FWIW, https://github.com/whatwg/dom/issues/new is the new place.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>