Skip to content

Commit

Permalink
fix: should only generate new id when cross doc (#9009)
Browse files Browse the repository at this point in the history
  • Loading branch information
Saul-Mirone committed Dec 18, 2024
1 parent a35ff22 commit 2c68ec0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { BlockStdScope } from '@blocksuite/block-std';
import type { JobMiddleware } from '@blocksuite/store';

export const newIdCrossDoc =
(std: BlockStdScope): JobMiddleware =>
({ slots, collection }) => {
let samePage = false;
slots.beforeImport.on(payload => {
if (payload.type === 'slice') {
samePage = payload.snapshot.pageId === std.doc.id;
}
if (payload.type === 'block' && !samePage) {
payload.snapshot.id = collection.idGenerator();
}
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
import { addNoteAtPoint } from '../../../edgeless/utils/common.js';
import { DropIndicator } from '../components/drop-indicator.js';
import { AFFINE_DRAG_HANDLE_WIDGET } from '../consts.js';
import { copyEmbedDoc } from '../middleware/copy-embed-doc.js';
import { newIdCrossDoc } from '../middleware/new-id-cross-doc.js';
import { surfaceRefToEmbed } from '../middleware/surface-ref-to-embed.js';
import { containBlock, includeTextSelection } from '../utils.js';

Expand Down Expand Up @@ -114,6 +114,7 @@ export class DragEventWatcher {

private _dropHandler = (context: UIEventStateContext) => {
this._onDrop(context);
this._std.selection.setGroup('gfx', []);
this.widget.clearRaf();
this.widget.hide(true);
};
Expand Down Expand Up @@ -437,7 +438,7 @@ export class DragEventWatcher {
const std = this._std;
return new Job({
collection: std.collection,
middlewares: [copyEmbedDoc, surfaceRefToEmbed(std)],
middlewares: [newIdCrossDoc(std), surfaceRefToEmbed(std)],
});
}

Expand Down
2 changes: 1 addition & 1 deletion tests/linked-page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ test('linked doc can be dragged from note to surface top level block', async ({
await dragBlockToPoint(page, '9', { x: 200, y: 200 });

await waitNextFrame(page);
await assertParentBlockFlavour(page, '10', 'affine:surface');
await assertParentBlockFlavour(page, '9', 'affine:surface');
});

// Aliases
Expand Down

0 comments on commit 2c68ec0

Please sign in to comment.