Skip to content

Range.extractContents() and Range.surroundContents() describe behaviour incorrectly #35854

@TAPgiles

Description

@TAPgiles

MDN URL

https://developer.mozilla.org/en-US/docs/Web/API/Range/extractContents

(Also https://developer.mozilla.org/en-US/docs/Web/API/Range/surroundContents)

What specific section or headline is this issue about?

No response

What information was incorrect, unhelpful, or incomplete?

Both pages describe:

moves content of the Range

This is not the behaviour as far as I can see in 126.0.6478.214 (Official Build) (64-bit), if a text node is the startContainer or endContainer or both. And is not the intended behaviour according to the spec:

To clone the contents of a live range range, run these steps...

(Unsure why that doesn't also apply to elements, but there you go.)

A range that is "partial" through text nodes (even if the offsets are at the beginning and end of the text nodes in question) will be cloned. They are not the original nodes. As such, they are not "moved." And that is the intended and correct behaviour. Therefore, the wording in the reference page is misleading at best or just wrong.

The closest I see to any explanation of this is in the extractContents() page:

Partially selected nodes are cloned to include the parent tags necessary to make the document fragment valid.

Which does not explain the definition of a "partially selected node" which is a misleading term anyway. In practise, the usage on the extractContents() page means "if a text node is the starting or ending boundary node." Whether or not all of that text node is included in the range.

And does not always have anything to do with parent tags. In fact, I've not been able to see any case in my testing where the parent tag is cloned. Maybe they are "included", but that term is not explained either and I cannot figure out what is meant by it.

What did you expect to see?

An accurate description of the behaviour, without unexplained terms, or with such terms properly explained:

The Range.extractContents() method moves all nodes within the Range from the document tree into a DocumentFragment. Where a text node is the starting or ending boundary of the Range, a clone of it is added to the fragment instead.

Do you have any supporting links, references, or citations?

No response

Do you have anything more you want to share?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Content:WebAPIWeb API docshelp wantedIf you know something about this topic, we would love your help!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions