Skip to content

fix(nodeUtil): moved blocks now included in the editor changes #1931

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/core/src/api/nodeUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,22 +184,25 @@ function collectAllBlocks<
{
block: Block<BSchema, ISchema, SSchema>;
parentId: string | undefined;
index: number;
}
> {
const blocks: Record<
string,
{
block: Block<BSchema, ISchema, SSchema>;
parentId: string | undefined;
index: number;
}
> = {};
const pmSchema = getPmSchema(doc);
doc.descendants((node, pos) => {
doc.descendants((node, pos, _, index) => {
if (isNodeBlock(node)) {
const parentId = getParentBlockId(doc, pos);
blocks[node.attrs.id] = {
block: nodeToBlock(node, pmSchema),
parentId,
index,
};
}
return true;
Expand Down Expand Up @@ -264,8 +267,9 @@ export function getBlocksChangedByTransaction<
const prev = prevBlocks[id];
const next = nextBlocks[id];
const isParentDifferent = prev.parentId !== next.parentId;
const isIndexDifferent = prev.index !== next.index;

if (isParentDifferent) {
if (isParentDifferent || isIndexDifferent) {
changes.push({
type: "move",
block: next.block,
Expand Down