[Bug 20654] Have Range.surroundContents() work for partially contained nodes?

https://www.w3.org/Bugs/Public/show_bug.cgi?id=20654

--- Comment #1 from Aryeh Gregor <ayg@aryeh.name> ---
I don't think extractContents() does what we want here.  That clones *existing*
containers.  In this case, I think expected behavior would be to clone the
*new* container.  So if you have a DOM of
  <p>foo</p><p>bar</p>
with "ob" selected, and do
  range.surroundContents(document.createElement("i"))
I would expect
  <p>fo<i>o</i></p><p><i>b</i>ar</p>
not
  <p>fo<i>o<p>b</p></i></p><p>ar</p>
which is what you'd get if you applied extractContents().  The latter effect is
much more disruptive, because you don't know what existing DOM structure you're
messing with -- e.g., the misnesting here.  It's also equivalent to
extractContents() + insertNode() + appendChild(), so no need for a separate
function.  The former behavior is closer to what you'd expect for a function
that aims to do things like "make selection bold" in a simple-minded fashion,
which I think is the goal of surroundContents().  The cloning shouldn't do
anything surprising if you pass simple nodes to it -- e.g., just pass
document.createElement() with some non-id attributes set and you're probably
fine even if it gets cloned a bunch.

Even with the change, though, this method is too simplistic to use for even
basic formatting.  If you have something like
  foo<font color=red>bar</font>baz
and try to select all the text and wrap in <font color=green> using this
method, it won't do what you want -- "bar" will remain red.  What's the
use-case for using this method even with the change?  Does anyone use it now,
and if so, for what?

-- 
You are receiving this mail because:
You are the QA Contact for the bug.

Received on Wednesday, 16 January 2013 12:20:18 UTC