<?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>15297</bug_id>
          
          <creation_ts>2011-12-21 09:34:53 +0000</creation_ts>
          <short_desc>Range.insertNode()</short_desc>
          <delta_ts>2011-12-28 19:59:14 +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>FIXED</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>adrianba</cc>
    
    <cc>ap</cc>
    
    <cc>ayg</cc>
    
    <cc>bugs</cc>
    
    <cc>ian</cc>
    
    <cc>jonas</cc>
    
    <cc>jrossi</cc>
    
    <cc>mike</cc>
    
    <cc>mjs</cc>
    
    <cc>ojan</cc>
    
    <cc>travil</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>61869</commentid>
    <comment_count>0</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2011-12-21 09:34:53 +0000</bug_when>
    <thetext>This is currently an open issue in the DOM standard: http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-range-insertnode

Aryeh&apos;s tests are testing for the Gecko behavior.

WebKit&apos;s bug is here https://bugs.webkit.org/show_bug.cgi?id=16867

Opera is leaning towards aligning with Gecko.

Feedback appreciated, especially from Microsoft.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>61949</commentid>
    <comment_count>1</comment_count>
    <who name="Ojan Vafai">ojan</who>
    <bug_when>2011-12-22 18:45:48 +0000</bug_when>
    <thetext>I don&apos;t really understand the note in the spec and the webkit bug seems generic for all insertNode related issues. Can you give an example or two where the behavior differs?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>61950</commentid>
    <comment_count>2</comment_count>
      <attachid>1054</attachid>
    <who name="Olli Pettay">bugs</who>
    <bug_when>2011-12-22 18:56:01 +0000</bug_when>
    <thetext>Created attachment 1054
testcase

Gecko selects nothing new, webkit selects the newly added text node</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>62049</commentid>
    <comment_count>3</comment_count>
    <who name="Jacob Rossi [MSFT]">jrossi</who>
    <bug_when>2011-12-27 18:34:03 +0000</bug_when>
    <thetext>We&apos;re aware that we differ from the spec. We implemented it this way to be interoperable with the majority of other browsers. Additionally, I think our behavior makes more sense for web devs than what the spec describes. I would expect that calling insertNode would imply that you move the end point to include the inserted node--in other words, the node is included in the selection.

If instead you first started with &lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;  and selected the contents of the div, then the offsets would be 0,1. Then, if you inserted another span using insertNode, it would be 0,2. 

I see no compelling reason why it should behave differently when collapsed--but we&apos;d be willing to entertain a change here if there&apos;s consensus that the spec&apos;d behavior is better for web developers.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>62051</commentid>
    <comment_count>4</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2011-12-27 19:08:53 +0000</bug_when>
    <thetext>Personally I&apos;m with you Jacob. I never quite understood why Olli thought the other behavior was better. I just don&apos;t care strongly either way :-)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>62052</commentid>
    <comment_count>5</comment_count>
    <who name="Olli Pettay">bugs</who>
    <bug_when>2011-12-27 19:14:02 +0000</bug_when>
    <thetext>I prefer consistency.
DOM 2 Range handled insertNode like normal DOM mutation.
DOM 4 requires some special handling.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>62053</commentid>
    <comment_count>6</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2011-12-27 19:16:31 +0000</bug_when>
    <thetext>But don&apos;t you expect the special handling given that you insert a node into a Range (collapsed or not)? That&apos;s the name of the method after all.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>62054</commentid>
    <comment_count>7</comment_count>
    <who name="Jacob Rossi [MSFT]">jrossi</who>
    <bug_when>2011-12-27 19:18:38 +0000</bug_when>
    <thetext>For what it&apos;s worth, I don&apos;t feel strongly about one or the other either. If all major browsers but one are interoperable, then I would think we&apos;d want a good reason why the currently spec&apos;d design is better for web developers in order to keep it. But if there&apos;s enough consensus that the spec&apos;d behavior is better, then I think we&apos;re open to considering a change. All in all, this is pretty minor.

Consistency is a good argument for web developers. Though, I feel that IE/Webkit/Opera&apos;s behavior is more predictable/consistent with my expectations--insertNode on a Range always selects the inserted node. Having it behave differently for the collapsed case actually seems more of an inconsistency to me (and in fact, would actually have to be a special case in our implementation if we changed it).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>62061</commentid>
    <comment_count>8</comment_count>
    <who name="Aryeh Gregor">ayg</who>
    <bug_when>2011-12-27 20:30:09 +0000</bug_when>
    <thetext>I&apos;m for changing to match IE/WebKit/Opera.  Their behavior makes at least as much sense as DOM 2 Range/Gecko, and moving to match it requires fewer UAs to change.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>62093</commentid>
    <comment_count>9</comment_count>
    <who name="Olli Pettay">bugs</who>
    <bug_when>2011-12-28 10:48:50 +0000</bug_when>
    <thetext>(In reply to comment #6)
&gt; But don&apos;t you expect the special handling given that you insert a node into a
&gt; Range (collapsed or not)? That&apos;s the name of the method after all.

Not sure. It depends on how one interprets &quot;insertNode&quot;. Whether it is 
insert a node into a Range, or insert node to the place the Range indicates. 
DOM 2 Range nicely allows both interpretations:
&quot;A node may be inserted into a Range&quot;
&quot;The node is inserted at the start boundary-point of the Range, without modifying it.&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>62094</commentid>
    <comment_count>10</comment_count>
    <who name="Olli Pettay">bugs</who>
    <bug_when>2011-12-28 10:50:10 +0000</bug_when>
    <thetext>DOM4 doesn&apos;t seem to say what the method is supposed to do,
it has just the pseudo-code.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>62095</commentid>
    <comment_count>11</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2011-12-28 10:51:52 +0000</bug_when>
    <thetext>We can add the non-normative descriptions once we decide on behavior.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>62113</commentid>
    <comment_count>12</comment_count>
    <who name="Aryeh Gregor">ayg</who>
    <bug_when>2011-12-28 19:59:14 +0000</bug_when>
    <thetext>Changed, as agreed with annevk on IRC:

http://dvcs.w3.org/hg/domcore/rev/c6ad35d540ae
http://dvcs.w3.org/hg/webapps/rev/0e0ccea27522

Sorry that this punishes Gecko for following (what used to be) the spec, but that&apos;s not as strong a consideration as matching the majority of browsers.  The spec now gets the offsets exactly the same as WebKit in all of my tests, differing from IE only in corner cases (I think -- couldn&apos;t check myself right now).</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>1054</attachid>
            <date>2011-12-22 18:56:01 +0000</date>
            <delta_ts>2011-12-22 18:56:01 +0000</delta_ts>
            <desc>testcase</desc>
            <filename>insertnode.html</filename>
            <type>text/html</type>
            <size>405</size>
            <attacher name="Olli Pettay">bugs</attacher>
            
              <data encoding="base64">PCFET0NUWVBFIGh0bWw+CjxodG1sPgogIDxoZWFkPgogICAgPHNjcmlwdD4KICAgIGZ1bmN0aW9u
IHRlc3QoKSB7CiAgICAgIGRvY3VtZW50LmJvZHkuaW5uZXJIVE1MID0gIiI7CiAgICAgIHZhciBy
ID0gZG9jdW1lbnQuY3JlYXRlUmFuZ2UoKTsKICAgICAgci5zZWxlY3ROb2RlQ29udGVudHMoZG9j
dW1lbnQuYm9keSk7CiAgICAgIHIuaW5zZXJ0Tm9kZShkb2N1bWVudC5jcmVhdGVUZXh0Tm9kZSgi
Zm9vIikpOwogICAgICBhbGVydCgiUmFuZ2UgYWZ0ZXIgaW5zZXJ0aW5nICdmb28nIHVzaW5nIHth
IGNvbGxhcHNlZCByYW5nZX0uaW5zZXJ0Tm9kZSgpOiBbIiArIHIgKyAiXSIpOwogICAgfQogICAg
PC9zY3JpcHQ+CiAgPC9oZWFkPgogIDxib2R5IG9ubG9hZD0idGVzdCgpIj4KICA8L2JvZHk+Cjwv
aHRtbD4K
</data>

          </attachment>
      

    </bug>

</bugzilla>