mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-18 02:21:51 +08:00
fix: wrong block order when pasting multiple blocks
This commit is contained in:
@@ -241,15 +241,12 @@ export class Paste {
|
|||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
selectedBlock.setProperties({
|
await selectedBlock.setProperties({
|
||||||
text: {
|
text: {
|
||||||
value: newTextValue,
|
value: newTextValue,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const pasteBlocks = await this._createBlocks(blocks);
|
const pastedBlocks = await this._createBlocks(blocks);
|
||||||
await Promise.all(
|
|
||||||
pasteBlocks.map(block => selectedBlock.after(block))
|
|
||||||
);
|
|
||||||
|
|
||||||
const nextBlock = await this._editor.createBlock(
|
const nextBlock = await this._editor.createBlock(
|
||||||
selectedBlock?.type
|
selectedBlock?.type
|
||||||
@@ -259,11 +256,12 @@ export class Paste {
|
|||||||
value: nextTextValue,
|
value: nextTextValue,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
pasteBlocks[pasteBlocks.length - 1].after(nextBlock);
|
|
||||||
|
|
||||||
this._setEndSelectToBlock(
|
await this._insertBlocksAfterBlock(selectedBlock, [
|
||||||
pasteBlocks[pasteBlocks.length - 1].id
|
...pastedBlocks,
|
||||||
);
|
nextBlock,
|
||||||
|
]);
|
||||||
|
await this._setEndSelectToBlock(nextBlock.id);
|
||||||
} else {
|
} else {
|
||||||
this._editor.blockHelper.insertNodes(
|
this._editor.blockHelper.insertNodes(
|
||||||
selectedBlock.id,
|
selectedBlock.id,
|
||||||
@@ -327,10 +325,7 @@ export class Paste {
|
|||||||
value: newTextValue,
|
value: newTextValue,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const pasteBlocks = await this._createBlocks(blocks);
|
const pastedBlocks = await this._createBlocks(blocks);
|
||||||
pasteBlocks.forEach((block: AsyncBlock) => {
|
|
||||||
selectedBlock.after(block);
|
|
||||||
});
|
|
||||||
const nextBlock = await this._editor.createBlock(
|
const nextBlock = await this._editor.createBlock(
|
||||||
selectedBlock?.type
|
selectedBlock?.type
|
||||||
);
|
);
|
||||||
@@ -339,11 +334,12 @@ export class Paste {
|
|||||||
value: nextTextValue,
|
value: nextTextValue,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
pasteBlocks[pasteBlocks.length - 1].after(nextBlock);
|
await this._insertBlocksAfterBlock(selectedBlock, [
|
||||||
|
...pastedBlocks,
|
||||||
|
nextBlock,
|
||||||
|
]);
|
||||||
|
|
||||||
this._setEndSelectToBlock(
|
await this._setEndSelectToBlock(nextBlock.id);
|
||||||
pasteBlocks[pasteBlocks.length - 1].id
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
this._editor.blockHelper.insertNodes(
|
this._editor.blockHelper.insertNodes(
|
||||||
selectedBlock.id,
|
selectedBlock.id,
|
||||||
@@ -353,10 +349,10 @@ export class Paste {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const pasteBlocks = await this._createBlocks(blocks);
|
const pastedBlocks = await this._createBlocks(blocks);
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
pasteBlocks.map(block => selectedBlock.after(block))
|
pastedBlocks.map(block => selectedBlock.after(block))
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isSelectedBlockEmpty) {
|
if (isSelectedBlockEmpty) {
|
||||||
@@ -364,7 +360,7 @@ export class Paste {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this._setEndSelectToBlock(
|
this._setEndSelectToBlock(
|
||||||
pasteBlocks[pasteBlocks.length - 1].id
|
pastedBlocks[pastedBlocks.length - 1].id
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -374,28 +370,39 @@ export class Paste {
|
|||||||
currentSelectInfo.blocks[currentSelectInfo.blocks.length - 1]
|
currentSelectInfo.blocks[currentSelectInfo.blocks.length - 1]
|
||||||
.blockId
|
.blockId
|
||||||
);
|
);
|
||||||
const pasteBlocks = await this._createBlocks(blocks);
|
const pastedBlocks = await this._createBlocks(blocks);
|
||||||
|
|
||||||
let groupBlock: AsyncBlock;
|
let groupBlock: AsyncBlock;
|
||||||
if (selectedBlock?.type === 'page') {
|
if (selectedBlock?.type === 'page') {
|
||||||
groupBlock = await this._editor.createBlock('group');
|
groupBlock = await this._editor.createBlock('group');
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
pasteBlocks.map(block => groupBlock.append(block))
|
pastedBlocks.map(block => groupBlock.append(block))
|
||||||
);
|
);
|
||||||
await selectedBlock.after(groupBlock);
|
await selectedBlock.after(groupBlock);
|
||||||
} else if (selectedBlock?.type === 'group') {
|
} else if (selectedBlock?.type === 'group') {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
pasteBlocks.map(block => selectedBlock.append(block))
|
pastedBlocks.map(block => selectedBlock.append(block))
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
pasteBlocks.map(block => selectedBlock.after(block))
|
pastedBlocks.map(block => selectedBlock.after(block))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
this._setEndSelectToBlock(pasteBlocks[pasteBlocks.length - 1].id);
|
this._setEndSelectToBlock(pastedBlocks[pastedBlocks.length - 1].id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async _insertBlocksAfterBlock(
|
||||||
|
targetBlock: AsyncBlock,
|
||||||
|
blocks: AsyncBlock[]
|
||||||
|
) {
|
||||||
|
if (blocks.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const [firstBlock, ...otherBlock] = blocks;
|
||||||
|
await targetBlock.after(firstBlock);
|
||||||
|
await this._insertBlocksAfterBlock(blocks[0], otherBlock);
|
||||||
|
}
|
||||||
private async _setEndSelectToBlock(blockId: string) {
|
private async _setEndSelectToBlock(blockId: string) {
|
||||||
const block = await this._editor.getBlockById(blockId);
|
const block = await this._editor.getBlockById(blockId);
|
||||||
const isBlockCanEdit = Paste._isTextEditBlock(block.type);
|
const isBlockCanEdit = Paste._isTextEditBlock(block.type);
|
||||||
|
|||||||
Reference in New Issue
Block a user