-
-
Notifications
You must be signed in to change notification settings - Fork 491
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
feature: add support for blocknote transactions #1147
base: refactor/clean-blockcontainer
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
/** | ||
* Dispatch a transaction, but only if not in a "blocknote transact". | ||
*/ | ||
public dispatch(tr: Transaction) { | ||
if (!this.activeTransaction) { | ||
this._tiptapEditor.dispatch(tr); | ||
} | ||
} | ||
|
||
/** | ||
* Execute a function within a "blocknote transaction". | ||
* All changes to the editor within the transaction will be grouped together, so that | ||
* we can dispatch them as a single operation (thus creating only a single undo step) | ||
*/ | ||
public transact(func: () => void) { | ||
this.activeTransaction = this._tiptapEditor.state.tr; | ||
try { | ||
func(); | ||
this._tiptapEditor.dispatch(this.activeTransaction); | ||
} finally { | ||
this.activeTransaction = undefined; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for awareness, Tiptap already has a way to capture transactions without immediately dispatching them: https://github.com/ueberdosis/tiptap/blob/44cae5badc07e715bf6554e7042a9e4e926e57b7/packages/core/src/Editor.ts#L414-L429
This is a POC for blocknote-level transactions. It should make it possible to clean our existing commands (those in
blockManipulation
further down by migrating away from tiptap-style commands). It also unlocks the possibility for userland-transactions.For example, the following bug is fixed:
closes https://github.com/TypeCellOS/BlockNote/issues?q=is%3Aissue+is%3Aopen+undo
TODO:
editor.state
? It's likely they should read the state from theactiveTransaction
instead (diagnose, create tests, and fix)transact