Skip to content

Not clear docs on Node.common() #5520

Open
@ch1ll0ut1

Description

@ch1ll0ut1

Problem
The documentation of Node.common can be a bit confusing vs the actual implementation because the docs say:

"Get an entry for the common ancestor node of two paths. It might be a Text node, an Element, or the Editor itself."

Solution
A better description would be:

"Get an entry for the common ancestor node of two paths or a text node if both paths are within the same text node. The returned node might be a Text node, an Element, or the Editor itself.

Because of this special case it does not always return an ancestor and as such the first sentence is wrong, and when reading the second sentence the question is: how can two path produce an ancestor which is also a text node? It's not possible (I believe). That's why for me the docs are confusing and I had to look up the source code to understand what's really happening.

Alternatives
Alternative would be to change the implementation to always return the ancestor even if the range is within a single text node.

Context
I'm trying to find an easy way to get the ancestor block from the current editor.selection and browsing through the docs.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions