W3C home > Mailing lists > Public > whatwg@whatwg.org > March 2011

[whatwg] DOM Range: redefining behavior under DOM mutation

From: Boris Zbarsky <bzbarsky@MIT.EDU>
Date: Tue, 29 Mar 2011 20:48:15 -0400
Message-ID: <4D927DCF.3000509@mit.edu>
On 3/29/11 5:53 PM, Aryeh Gregor wrote:
> So is anyone planning on actually trying to remove DOM mutation events, or not?

I think Jonas is still planning on it; we just need to implement a 
replacement for them first...

> Just something simple like running execCommand("bold") when "bar" is
> selected in fairly trivial markup like
>
>    <p><b>Foo</b>bar</p>
>
> The result will be that "bar" is still selected but now wrapped in the
> same<b>  as "Foo", which isn't the result you'd get using any sequence
> of JavaScript-visible DOM method calls I can think of.

I haven't looked up the details of how we implement this (because it 
really is a huge pain; let me know if you want me to do that), but the 
behavior you describe is the result of doing this:

  var range = getSelectionRange(); /* However you implement this */
  var b = document.createElement("b");
  range.surroundContents(b);

The range is explicitly repositioned by the end of the surroundContents 
algorithm.

-Boris
Received on Tuesday, 29 March 2011 17:48:15 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:31 UTC