[whatwg] DOM Range: redefining behavior under DOM mutation

Boris Zbarsky bzbarsky at MIT.EDU
Tue Mar 29 17:48:15 PDT 2011


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



More information about the whatwg mailing list