<?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>13153</bug_id>
          
          <creation_ts>2011-07-05 20:40:13 +0000</creation_ts>
          <short_desc>replaceData() should insert before deleting, to give better range mutation behavior</short_desc>
          <delta_ts>2011-07-14 14:44:44 +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>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>enhancement</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Aryeh Gregor">ayg</reporter>
          <assigned_to name="Anne">annevk</assigned_to>
          <cc>jonas</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>50694</commentid>
    <comment_count>0</comment_count>
    <who name="Aryeh Gregor">ayg</who>
    <bug_when>2011-07-05 20:40:13 +0000</bug_when>
    <thetext>Testcase:

http://software.hixie.ch/utilities/js/live-dom-viewer/saved/1062

This does replaceData(1, 1, &quot;uu&quot;) on a text node &quot;foo&quot;.  A range collapsed like &quot;fo[]o&quot; then becomes &quot;f[]uuo&quot; per the current spec.  This is because first you delete one character, so it becomes &quot;f[]o&quot;, then you insert the new characters, and insertions always go after a boundary point.  If you instead inserted them before the substring to be deleted, then deleted the substring, it would first be &quot;fuuo[]o&quot;, then &quot;fuu[]o&quot;.  Then the boundary point goes where it logically belongs -- after the replacement for the thing it was already after.

The current spec matches the behavior of IE9, Firefox 6.0a2, and Chrome 14 dev (they log &quot;1&quot; in the test).  Opera 11.50 matches my proposed behavior (logs &quot;3&quot;).  I don&apos;t think this would affect compat, so switching to Opera&apos;s behavior should be safe.

To be clear, I&apos;m asking that the spec be changed to say something like

&quot;The replaceData(offset, count, data) method must act as if the insertData() method is invoked with offset and data as arguments followed by the deleteData() method with (offset + data.length) and count as arguments and re-throw any exceptions these methods might have thrown.&quot;

AFAIK, this should only affect range mutations (for the better) and mutation events (unlikely to make a compat difference, I hope).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>50708</commentid>
    <comment_count>1</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2011-07-06 08:23:04 +0000</bug_when>
    <thetext>We should also change to not describe this method in terms of other methods so when we land mutation listeners only one mutation is done for the whole operation.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>50749</commentid>
    <comment_count>2</comment_count>
    <who name="Aryeh Gregor">ayg</who>
    <bug_when>2011-07-06 20:32:02 +0000</bug_when>
    <thetext>If you do that, you can close this bug.  DOM Range will need to special-case replaceData() then anyway.  You reminded me to file bug 13164, though, which is a better way of handling integration with stuff like range mutations and mutation events IMO.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>51005</commentid>
    <comment_count>3</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2011-07-14 11:44:27 +0000</bug_when>
    <thetext>Can you look at the current text to see whether it is okay?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>51019</commentid>
    <comment_count>4</comment_count>
    <who name="Aryeh Gregor">ayg</who>
    <bug_when>2011-07-14 14:44:44 +0000</bug_when>
    <thetext>Looks good to me, thanks!</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>