mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-01 06:10:16 +08:00
fix(editor): exisiting slice import should be move instead of add (#9616)
Closes: [BS-2339](https://linear.app/affine-design/issue/BS-2339/%E6%8B%96%E6%8B%BD%E9%87%8A%E6%94%BE%E5%90%8E%E7%9A%84%E4%BD%8D%E7%BD%AE%E4%B8%8D%E5%AF%B9)
This commit is contained in:
@@ -256,7 +256,26 @@ export class Job {
|
||||
|
||||
const blockTree = await this._convertFlatSnapshots(flatSnapshots);
|
||||
|
||||
await this._insertBlockTree(blockTree.children, doc, parent, index);
|
||||
const first = content[0];
|
||||
// check if the slice is already in the doc
|
||||
if (first && doc.hasBlock(first.id)) {
|
||||
// if the slice is already in the doc, we need to move the blocks instead of adding them
|
||||
const models = flatSnapshots
|
||||
.map(flat => doc.getBlock(flat.snapshot.id)?.model)
|
||||
.filter(Boolean) as BlockModel[];
|
||||
const parentModel = parent ? doc.getBlock(parent)?.model : undefined;
|
||||
if (!parentModel) {
|
||||
throw new BlockSuiteError(
|
||||
ErrorCode.TransformerError,
|
||||
'Parent block not found in doc when moving slice'
|
||||
);
|
||||
}
|
||||
const targetSibling =
|
||||
index !== undefined ? parentModel.children[index] : null;
|
||||
doc.moveBlocks(models, parentModel, targetSibling);
|
||||
} else {
|
||||
await this._insertBlockTree(blockTree.children, doc, parent, index);
|
||||
}
|
||||
|
||||
const contentBlocks = blockTree.children
|
||||
.map(tree => doc.getBlockById(tree.draft.id))
|
||||
|
||||
Reference in New Issue
Block a user