This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 13153 - replaceData() should insert before deleting, to give better range mutation behavior
Summary: replaceData() should insert before deleting, to give better range mutation be...
Status: RESOLVED FIXED
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: DOM (show other bugs)
Version: unspecified
Hardware: All All
: P2 enhancement
Target Milestone: ---
Assignee: Anne
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-05 20:40 UTC by Aryeh Gregor
Modified: 2011-07-14 14:44 UTC (History)
3 users (show)

See Also:


Attachments

Description Aryeh Gregor 2011-07-05 20:40:13 UTC
Testcase:

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

This does replaceData(1, 1, "uu") on a text node "foo".  A range collapsed like "fo[]o" then becomes "f[]uuo" per the current spec.  This is because first you delete one character, so it becomes "f[]o", 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 "fuuo[]o", then "fuu[]o".  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 "1" in the test).  Opera 11.50 matches my proposed behavior (logs "3").  I don't think this would affect compat, so switching to Opera's behavior should be safe.

To be clear, I'm asking that the spec be changed to say something like

"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."

AFAIK, this should only affect range mutations (for the better) and mutation events (unlikely to make a compat difference, I hope).
Comment 1 Anne 2011-07-06 08:23:04 UTC
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.
Comment 2 Aryeh Gregor 2011-07-06 20:32:02 UTC
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.
Comment 3 Anne 2011-07-14 11:44:27 UTC
Can you look at the current text to see whether it is okay?
Comment 4 Aryeh Gregor 2011-07-14 14:44:44 UTC
Looks good to me, thanks!