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
5.9k stars 384 forks source link

Calling `editor.updateBlock()` in quick succession breaks the editor's undo/redo functionality #829

Open balu-deciphr opened 3 weeks ago

balu-deciphr commented 3 weeks ago

Describe the bug I'm using an (old) example from the docs to highlight blocks spanned by the current selection. The highlighting works just fine, but this seems to break the editor's undo/redo functionality.

To Reproduce The demo is here.

To reproduce the issue, please do the following:

  1. Type something in the initialized content
  2. Press ctrl + z or cmd + z to undo what you typed. It will take multiple attempts to undo just one character.
  3. Remove the onSelectionChange prop from <BlockNoteView />
  4. Type something again in the editor
  5. Now the undo should work just fine.

It looks like the editor.updateBlock() calls within the editor.forEachBlock() causes the editor's history to break. Is there an alternate way to update the style of blocks?

Misc

matthewlipski commented 3 weeks ago

Good catch! You're right, it does seem like calling updateBlock many times in a short time causes history to break. Seems like we should make it possible to update multiple blocks at once to prevent this.