Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scroll Jump when adding new Block #1562

Open
1 task
tyouwei opened this issue Mar 25, 2025 · 2 comments
Open
1 task

Scroll Jump when adding new Block #1562

tyouwei opened this issue Mar 25, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@tyouwei
Copy link

tyouwei commented Mar 25, 2025

Describe the bug
When adding a new block directly before a large one, Blocknote's view will jump to the next available text cursor position instead of staying at its current scroll position. This can be slightly annoying for users adding consecutive files or images.

Somehow, this issue does not exist if we use the slash menu, it happens only when we use the '+' button

To Reproduce

  1. Add a very large image, or 2 large images consecutively
  2. Attempt to insert a new block right before the image blocks (must be a non-text based block)
  3. You will observe that the view automatically jumps to the end of the images (my observation is it always jumps to the next available text cursor

Misc

  • Node version: (whatever that blocknote's documentation is using)
  • Package manager: (whatever that blocknote's documentation is using)
  • Browser: Bug exists on Chrome and Edge
  • I'm a sponsor and would appreciate if you could look into this sooner than later 💖
Comments.Threads.-.BlockNote.-.Google.Chrome.2025-03-25.15-04-48.mp4
@tyouwei tyouwei added the bug Something isn't working label Mar 25, 2025
@tyouwei
Copy link
Author

tyouwei commented Mar 26, 2025

Did some research and found out the issue seems to be in the insertOrUpdateBlock function defined in here: https://github.com/TypeCellOS/BlockNote/blob/main/packages/core/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts

if (
    Array.isArray(currentBlock.content) &&
    ((currentBlock.content.length === 1 &&
      isStyledTextInlineContent(currentBlock.content[0]) &&
      currentBlock.content[0].type === "text" &&
      currentBlock.content[0].text === "/") ||
      currentBlock.content.length === 0)
  ) {
    newBlock = editor.updateBlock(currentBlock, block);
    // We make sure to reset the cursor position to the new block as calling
    // `updateBlock` may move it out. This generally happens when the content
    // changes, or the update makes the block multi-column.
    editor.setTextCursorPosition(newBlock);
  } else {
    newBlock = editor.insertBlocks([block], currentBlock, "after")[0];
    editor.setTextCursorPosition(editor.getTextCursorPosition().nextBlock!);
  }

BlockNote really is setting the selection to the next content editable block rather than the newly created one

@lawrencenika
Copy link

Having the same issue here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants