[webkit-help] How to use DOMRange to select a paragraph's outer HTML?

Alexander Shulgin alexander.shulgin at yessoftware.com
Mon May 17 10:00:49 PDT 2010


I'm new to the list, so hope this is the right place for my question. 
Feel free to redirect me to more appropriate one if it's not.

In the content editing mode is there a way to programmatically select 
_outer_ representation of a HTML tag, e.g. <p>, so that when we call one 
of the replaceSelectionWith*() methods, the selected tag is replaced as 
a whole?

I'm trying to use setSelectedDOMRange() like this:

DOMRange* range = ...;


But this has unpleasant side effects: any adjacent tags are merged into 
the newly inserted paragraph.  And this can be quite annoying as it 
would happily convert any adjacent <h1> into <span>, while preserving 
the look, but not semantics of HTML.

I understand this happens because in its internals WebKit uses visual 
caret positions, so selecting past the end of a <p> contents inevitably 
wraps upto contents of any following tag.

But what can I do about that?  I cannot seem to find a workaround even 
after stepping through WebCore code for a few days now.

Any help is greatly appreciated!

More information about the webkit-help mailing list