TypeCellOS / TypeCellOS/BlockNote

Can't select a single block

Open
#2,708 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
10.2k
Forks
772
Avg merge
3d 11h
Merged PRs (30d)
17

Description

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 💖

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the setSelection API described in the linked cursor-selections documentation and reproduce the issue using identical startBlock and endBlock IDs. Check the related setTextCursorPosition behavior and ensure selecting one block works from its start through its end without throwing; verify the custom SideMenu and FormattingToolbar use case through editor.getSelection().

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.