fix(editor): can not select the block after undo the drag from canvas to note (#12473)

Close [BS-3509](https://linear.app/affine-design/issue/BS-3509/embed拖入note,然后撤销,形成的block刷新后才可选中,且只能进行有限交互)

### Before

https://github.com/user-attachments/assets/4c83f9ba-1a99-427f-824d-7e946e55e737

### After

https://github.com/user-attachments/assets/e6a28478-0af4-4358-a353-e0c2e8edb0f9

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

- **Bug Fixes**
	- Improved block selection reliability after dragging a block into a note and performing an undo action, ensuring the block remains selectable.

- **Tests**
	- Added an end-to-end test to verify block selection after dragging and undo operations in edgeless mode.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
L-Sun
2025-05-23 07:28:30 +00:00
parent 41781902f6
commit 0902b2b9c9
4 changed files with 43 additions and 19 deletions

View File

@@ -200,7 +200,6 @@ export class GfxController extends LifeCycleWatcher {
...options,
all: true,
});
let picked = last(results) ?? null;
const { activeGroup } = selectionManager;
const first = picked;

View File

@@ -397,22 +397,14 @@ export class GridManager extends GfxExtension {
if (payload.type === 'add' && canBeRenderedAsGfxBlock(payload.model)) {
this.add(payload.model);
}
if (payload.type === 'update') {
const model = store.getBlock(payload.id)
?.model as GfxBlockElementModel;
if (!model) {
return;
}
const model = store.getModelById(payload.id);
if (!model) return;
if (payload.props.key === 'xywh' && canBeRenderedAsGfxBlock(model)) {
this.update(
store.getBlock(payload.id)?.model as GfxBlockElementModel
);
this.update(model);
}
}
if (
payload.type === 'delete' &&
payload.model instanceof GfxBlockElementModel
@@ -429,22 +421,28 @@ export class GridManager extends GfxExtension {
});
const watchSurface = (surface: SurfaceBlockModel) => {
let lastChildMap = new Map(surface.childMap.peek());
let lastChildMap = new Map<string, number>(surface.childMap.peek());
disposables.add(
surface.childMap.subscribe(val => {
val.forEach((_, id) => {
surface.childMap.subscribe(currentChildMap => {
currentChildMap.forEach((_, id) => {
if (lastChildMap.has(id)) {
lastChildMap.delete(id);
return;
}
});
lastChildMap.forEach((_, id) => {
const block = store.getBlock(id);
if (block?.model) {
this.remove(block.model as GfxBlockElementModel);
const model = store.getModelById(id);
if (model) {
this.remove(model as GfxBlockElementModel);
}
});
lastChildMap = new Map(val);
currentChildMap.forEach((_, id) => {
const model = store.getModelById(id);
if (model) {
this.add(model as GfxBlockElementModel);
}
});
lastChildMap = new Map(currentChildMap);
})
);