Skip to content

Commit 4a3d364

Browse files
committed
chore: use replace step to insert blocks
1 parent 77f1bee commit 4a3d364

File tree

1 file changed

+7
-2
lines changed
  • packages/core/src/api/blockManipulation/commands/insertBlocks

1 file changed

+7
-2
lines changed

packages/core/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Node } from "prosemirror-model";
1+
import { Fragment, Node, Slice } from "prosemirror-model";
22

33
import { Block, PartialBlock } from "../../../../blocks/defaultBlocks.js";
44
import type { BlockNoteEditor } from "../../../../editor/BlockNoteEditor";
@@ -11,6 +11,7 @@ import {
1111
import { blockToNode } from "../../../nodeConversions/blockToNode.js";
1212
import { nodeToBlock } from "../../../nodeConversions/nodeToBlock.js";
1313
import { getNodeById } from "../../../nodeUtil.js";
14+
import { ReplaceStep } from "prosemirror-transform";
1415

1516
export function insertBlocks<
1617
BSchema extends BlockSchema,
@@ -43,7 +44,11 @@ export function insertBlocks<
4344
pos += posInfo.node.nodeSize;
4445
}
4546

46-
editor.dispatch(tr.insert(pos, nodesToInsert));
47+
tr.step(
48+
new ReplaceStep(pos, pos, new Slice(Fragment.from(nodesToInsert), 0, 0))
49+
);
50+
51+
editor.dispatch(tr);
4752

4853
// Now that the `PartialBlock`s have been converted to nodes, we can
4954
// re-convert them into full `Block`s.

0 commit comments

Comments
 (0)