Skip to content

How to select text/node inside block programmatically? #13976

@tonyAndr

Description

@tonyAndr

I'm looking for any alternative to TinyMCE's editor.selection.select() functionality or any other way to select DOM node or text by it's position in the document.

In my case: I have a plugin, which shows all links from the article's content in the sidebar panel.
When I click on any of those links, I want it to be selected (highlighted) in the editor.

The problem is, I can't find any documentation about selection functionality in Gutenberg, and standart
window.getSelection/addRange isn't working as expected (it works once, but then there is no way to remove selection - .removeRange / .removeAllRanges or addRange(someNewRange) make no effect when another link clicked in the sidebar).

What is the best way to find a piece of text or DOM node (by selector), which could be in any block and then select it (not a whole block, only particular text/node)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] Rich TextRelated to the Rich Text component that allows developers to render a contenteditable[Type] EnhancementA suggestion for improvement.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions