<?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>13843</bug_id>
          
          <creation_ts>2011-08-19 21:42:00 +0000</creation_ts>
          <short_desc>Define Range mutation for normalize()</short_desc>
          <delta_ts>2012-03-21 21:18:07 +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>normal</bug_severity>
          <target_milestone>---</target_milestone>
          <dependson>13868</dependson>
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Aryeh Gregor">ayg</reporter>
          <assigned_to name="Anne">annevk</assigned_to>
          <cc>adamk</cc>
    
    <cc>annevk</cc>
    
    <cc>bugs</cc>
    
    <cc>jrossi</cc>
    
    <cc>mike</cc>
    
    <cc>public-webapps</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>55511</commentid>
    <comment_count>0</comment_count>
    <who name="Aryeh Gregor">ayg</who>
    <bug_when>2011-08-19 21:42:00 +0000</bug_when>
    <thetext>We already special-case splitText().  normalize() should be special-cased too.  See Mozilla bug:

https://bugzilla.mozilla.org/show_bug.cgi?id=191864</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>55512</commentid>
    <comment_count>1</comment_count>
    <who name="Olli Pettay">bugs</who>
    <bug_when>2011-08-19 21:57:07 +0000</bug_when>
    <thetext>Just to remind, for some reason normalize() is removed from
http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-core
atm

(I think normalize() is useful, and if splitText() has special case in
range spec, so should normalize() have. Personally I think neither of them
should be special cased, but I don&apos;t care too much)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>55514</commentid>
    <comment_count>2</comment_count>
    <who name="Aryeh Gregor">ayg</who>
    <bug_when>2011-08-19 22:07:37 +0000</bug_when>
    <thetext>Hmm, that&apos;s weird.  normalize() is useful, I&apos;ve used it.  It should be re-added.  (This might explain why I didn&apos;t special-case it, because I didn&apos;t see it in the spec.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>55595</commentid>
    <comment_count>3</comment_count>
    <who name="Aryeh Gregor">ayg</who>
    <bug_when>2011-08-22 19:48:20 +0000</bug_when>
    <thetext>Filed bug 13868.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>61837</commentid>
    <comment_count>4</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2011-12-20 19:52:45 +0000</bug_when>
    <thetext>Is this done by virtue of reusing other algorithms?

http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-node-normalize</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>62059</commentid>
    <comment_count>5</comment_count>
    <who name="Aryeh Gregor">ayg</who>
    <bug_when>2011-12-27 20:14:43 +0000</bug_when>
    <thetext>Test-case:

data:text/html,&lt;!DOCTYPE html&gt;
&lt;script&gt;
var range = document.createRange();
document.head.appendChild(document.createTextNode(&quot;abc&quot;));
range.setStart(document.head.lastChild, 2);
document.head.appendChild(document.createTextNode(&quot;def&quot;));
range.setEnd(document.head.lastChild, 2);
document.head.normalize();
alert(range.startContainer + &quot;,&quot; + range.startOffset + &quot;,&quot; + range.endContainer + &quot;,&quot; + range.endOffset);
&lt;/script&gt;

Chrome 17 dev and Firefox 12.0a1 both alert &quot;[object Text],2,[object Text],5&quot; (so ab[cde]f stays selected).  Opera Next 12.00 alpha gives &quot;[object Text],2,[object HTMLHeadElement],2&quot; (changing selection to ab[cdef}).  I don&apos;t have IE to test.  The spec requires &quot;[object Text],2,[object Text],6&quot;, as far as I read it (changing selection to ab[cdef]).  Basically, unless Gecko and WebKit are both willing to drop their special-case behavior, we should add similar behavior to the spec.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>62091</commentid>
    <comment_count>6</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2011-12-28 09:23:03 +0000</bug_when>
    <thetext>IE9 gives &quot;[object HTMLHeadElement],1,[object Text],3&quot;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>62104</commentid>
    <comment_count>7</comment_count>
    <who name="Aryeh Gregor">ayg</who>
    <bug_when>2011-12-28 16:41:43 +0000</bug_when>
    <thetext>In that case, I still say we go with Gecko/WebKit, since it&apos;s the most interoperable right now.  The spec doesn&apos;t match anyone.  The spec should probably go something like this:

&quot;&quot;&quot;
For each Text node descendant of the context object:

1. Let node be the Text node descendant.

2. Let previous sibling be node&apos;s previous sibling.

3. If previous sibling is not a Text node, continue with the next Text node descendant of the context object.

4. Let length be previous sibling&apos;s length attribute value.

4. Replace data with node previous sibling, offset length, count 0, and data node&apos;s data.

5. For each boundary point whose node is node, increase its offset by length and set its node to previous sibling.

6. Remove node.
&quot;&quot;&quot;

Does that sound good?  If so, I&apos;ll write some tests and make the change.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>62105</commentid>
    <comment_count>8</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2011-12-28 16:47:35 +0000</bug_when>
    <thetext>If you have three Text-nodes the operation described does not seem ideal. Also, for mutation observers, do we want a single MutationRecord for each set of contiguous Text nodes affected? Because that would not work either with this description.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>62107</commentid>
    <comment_count>9</comment_count>
    <who name="Aryeh Gregor">ayg</who>
    <bug_when>2011-12-28 17:24:47 +0000</bug_when>
    <thetext>Well, you need one MutationRecord for each CharacterData change anyway, but yes, we could get away with fewer childList changes than my text allows.  Although we&apos;d have to define &quot;remove&quot; for multiple nodes at a time.  How about:

&quot;&quot;&quot;
For each Text node descendant of the context object:

1. Let node be the Text node descendant.

2. Let length be node&apos;s length attribute value.

3. Let data be the concatenation of the data of node&apos;s contiguous Text nodes (excluding itself), in tree order.

4. Replace data with node node, offset length, count 0, and data data.

5. Let current node be node&apos;s next sibling.

6. While current node is a Text node:

  1. For each boundary point whose node is current node, add length to its offset and set its node to node.

  2. Add current node&apos;s length attribute value to length.

  3. Set current node to its next sibling.

7. Remove node&apos;s contiguous Text nodes (excluding itself), in tree order.
&quot;&quot;&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>62108</commentid>
    <comment_count>10</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2011-12-28 17:45:41 +0000</bug_when>
    <thetext>My point was that you&apos;d only need one &quot;characterData&quot; MutationRecord for three consecutive Text nodes. The comment 9 algorithm also replaces when there&apos;s no need. Other than that I suppose it&apos;s okay. (Until we add mutation observers.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>65894</commentid>
    <comment_count>11</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2012-03-21 12:09:31 +0000</bug_when>
    <thetext>Aryeh, can you have another look at this now we have mutation observers? I don&apos;t think there&apos;s a need to optimize removal anymore.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>65905</commentid>
    <comment_count>12</comment_count>
    <who name="Aryeh Gregor">ayg</who>
    <bug_when>2012-03-21 19:16:16 +0000</bug_when>
    <thetext>Is there anything wrong with the algorithm in comment 9 now, relative to the current spec&apos;s algorithm?  If not, I&apos;ll change the spec.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>65907</commentid>
    <comment_count>13</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2012-03-21 19:25:16 +0000</bug_when>
    <thetext>So why do you need to manually update the boundary points? Does concept-node-remove not take care of that?

Also currently the other text updating Ranges does not use the boundary points terminology. Still not quite sure whether it should.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>65910</commentid>
    <comment_count>14</comment_count>
    <who name="Aryeh Gregor">ayg</who>
    <bug_when>2012-03-21 19:51:02 +0000</bug_when>
    <thetext>(In reply to comment #13)
&gt; So why do you need to manually update the boundary points? Does
&gt; concept-node-remove not take care of that?

That will collapse the boundary point to the end of the node.  See comment 5 -- the selected text should remain &quot;ab[cde]f&quot;, but per spec it would become &quot;ab[cdef]&quot;.

&gt; Also currently the other text updating Ranges does not use the boundary points
&gt; terminology. Still not quite sure whether it should.

Okay, I can modify it for that.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>65915</commentid>
    <comment_count>15</comment_count>
    <who name="Aryeh Gregor">ayg</who>
    <bug_when>2012-03-21 21:18:07 +0000</bug_when>
    <thetext>https://bitbucket.org/ms2ger/dom-core/changeset/bd9c816a31da

No tests for now, but I added a TODO to the mutation tests.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>