TypeCellOS / BlockNote

A React Rich Text Editor that's block-based (Notion style) and extensible. Built on top of Prosemirror and Tiptap.
https://www.blocknotejs.org/
Mozilla Public License 2.0
6.46k stars 440 forks source link

Typed or Copied Content Replaces Custom Alert Block Instead of Staying Within It #771

Open lamtuanamc opened 4 months ago

lamtuanamc commented 4 months ago

Description: I have customized a block type "alert" followed by a custom block on the BlockNote homepage. However, every time I type '-', '*', '+', '1.' or copy a text segment within the same editor, it replaces the "alert" block instead of placing the content within it.

Steps to Reproduce:

  1. Create a custom "alert" block as per the documentation.
  2. Type '-', '*', '+', '1.' or copy and paste a text segment within the "alert" block.
  3. Observe that the content replaces the "alert" block instead of staying within it.

Expected Behavior: The typed or copied content should remain within the "alert" block instead of replacing it.

Actual Behavior: The "alert" block is replaced by the typed or copied content.

https://github.com/TypeCellOS/BlockNote/assets/37234239/b9ebe406-f2de-4b79-b3c7-d7b8d456ced9

Link to Documentation: BlockNote Custom Schemas - Custom Blocks

YousefED commented 4 months ago

I agree this is undesirable. It should probably be fixed here: https://github.com/TypeCellOS/BlockNote/blob/bea361e39846c26d9729a777a5cd3de1f48e8c3e/packages/core/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts#L49 (and in the code for related shortcuts)

lamtuanamc commented 1 month ago

@YousefED If I remove this line, won't the regular text lines be unable to trigger the creation of a list? Or is there a way to check so that other blocks are not affected?

matthewlipski commented 1 month ago

You might want to call getBlockInfoFromPos instead and check if the block type is part of the default blocks:

const { contentType } = getBlockInfoFromPos(
  this.editor.state.doc,
  this.editor.state.selection.anchor
);

if (contentType.name in defaultBlockSpecs) {
  return true;
}