Skip to content

Can't select a single block #2708

@piemasters

Description

@piemasters

What’s broken?

It is not possible to select a single block via the setSelection function or seemingly any other way. Passing the same block or block id throws the error:
Attempting to set selection with the same anchor and head blocks (id ${startBlockId}).

The following also does not set the selection for the given block:

editor.setTextCursorPosition(block.id, "start");
editor.focus();

What did you expect to happen?

editor.setSelection(block.id); or editor.setSelection(block.id, block.id); should select a single block from its start to its end.

Steps to reproduce

  1. Using the setSelection function pass it the same block id for the startBlock and endBlock.
  2. The error is thrown, rather than the block being selected from beginning to end.

BlockNote version

0.47.1

Environment

React 18.2

Additional context

I'm currently trying to build a custom SideMenu button that on click selects the corresponding block and opens a custom FormattingToolbar that uses editor.getSelection().

Contribution

  • I'd be interested in contributing a fix for this issue

Sponsor

  • I'm a sponsor and would appreciate if you could look into this sooner than later 💖

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triageIssue has not yet been reviewed or classified by maintainers.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions