Comments: Diff and patch for DOM trees?

Diffing two DOM trees sounds like a poor way to implement undo and redo for a DOM editing tool. Consider what happens when you have a very large document. You wouldn't want to have crawl the entire before and after DOM to generate a diff. That would just be too expensive. It would seem to be much better to observe mutation events on the DOM, and then simply remember what changed as the changes are made.

(From Alex: I agree 100%. Unfortunately, that's not what happens when people want to edit source code directly. How do you go about undoing a change to innerHTML, for example? It's a poor example, because XML doesn't support innerHTML, but it's essentially how Mozilla Composer works. Composer doesn't try. I only want this feature to apply when the user switches from source code mode to a different mode.

However, I am considering what you've suggested, and I'm trying to come up with other ways to do this.)

Posted by Darin Fisher at May 15, 2005 12:29 PM

Arbitrary diff of two DOM trees is a very hard problem. I wanted to do it for the DSML Tools, but ended up doing something which was specific to the DSML DOM because the general problem is too tough. There were no open source libraries to do it available at the time (2000) either.

Posted by Gerv at May 16, 2005 5:40 AM