Skip to content

Commit ffc4a5b

Browse files
committed
fix: apply plugin appendedTransactions
1 parent 3dc0fcd commit ffc4a5b

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

packages/core/src/editor/BlockNoteEditor.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,12 @@ import {
9494
import { Dictionary } from "../i18n/dictionary.js";
9595
import { en } from "../i18n/locales/index.js";
9696

97-
import { Plugin, TextSelection, Transaction } from "@tiptap/pm/state";
97+
import {
98+
Plugin,
99+
TextSelection,
100+
Transaction,
101+
Selection as ProsemirrorSelection,
102+
} from "@tiptap/pm/state";
98103
import { dropCursor } from "prosemirror-dropcursor";
99104
import { EditorView } from "prosemirror-view";
100105
import { ySyncPluginKey } from "y-prosemirror";
@@ -738,7 +743,28 @@ export class BlockNoteEditor<
738743
*/
739744
public dispatch(tr: Transaction) {
740745
if (this.activeTransaction) {
741-
// We don't want the editor to actually apply the state, so all of this is manipulating the current transaction in-memory
746+
// The user wanted to dispatch, but we are already in a transaction, so we don't want to apply the state
747+
748+
// We do want to append any transactions though, so we'll do that
749+
const { transactions } = this._tiptapEditor.state.applyTransaction(tr);
750+
751+
this.activeTransaction = transactions.reduce((activeTr, trToApply) => {
752+
trToApply.steps.forEach((step) => {
753+
activeTr.step(step);
754+
});
755+
if (trToApply.selectionSet) {
756+
// Serialize the selection to JSON, because the document between the `activeTransaction` and the dispatch'd tr are different references
757+
activeTr.setSelection(
758+
ProsemirrorSelection.fromJSON(
759+
this.activeTransaction!.doc,
760+
trToApply.selection.toJSON()
761+
)
762+
);
763+
}
764+
765+
return activeTr;
766+
});
767+
742768
return;
743769
}
744770

0 commit comments

Comments
 (0)