@@ -94,7 +94,12 @@ import {
94
94
import { Dictionary } from "../i18n/dictionary.js" ;
95
95
import { en } from "../i18n/locales/index.js" ;
96
96
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" ;
98
103
import { dropCursor } from "prosemirror-dropcursor" ;
99
104
import { EditorView } from "prosemirror-view" ;
100
105
import { ySyncPluginKey } from "y-prosemirror" ;
@@ -738,7 +743,28 @@ export class BlockNoteEditor<
738
743
*/
739
744
public dispatch ( tr : Transaction ) {
740
745
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
+
742
768
return ;
743
769
}
744
770
0 commit comments