fix(editor): prevent errors when moving a block to its own position (#9887)

This commit is contained in:
L-Sun
2025-01-24 12:55:55 +00:00
parent 4b553d153a
commit 351816b343
2 changed files with 61 additions and 1 deletions

View File

@@ -264,6 +264,28 @@ export class DocCRUD {
targetSibling: string | null = null,
shouldInsertBeforeSibling = true
) {
if (
blocksToMove.length > 1 &&
targetSibling &&
blocksToMove.includes(targetSibling)
) {
console.error(
'Cannot move blocks when the target sibling is in the blocks to move'
);
return;
}
if (blocksToMove.length === 1 && targetSibling === blocksToMove[0]) {
return;
}
if (blocksToMove.includes(newParent)) {
console.error(
'Cannot move blocks when the new parent is in the blocks to move'
);
return;
}
// A map to store parent block and their respective child blocks
const childBlocksPerParent = new Map<string, string[]>();