From 625e8392a67de4f73457a50fe4a26947e410606e Mon Sep 17 00:00:00 2001 From: L-Sun Date: Thu, 29 May 2025 11:04:01 +0000 Subject: [PATCH] fix(editor): missing block in select-all set (#12627) This PR fixed that the block is missing in the selecte-all set after undo a dragging from canvas to note. Related to #12473 ### Before https://github.com/user-attachments/assets/828b4f48-689a-4975-bba6-f380f324de3c ### After https://github.com/user-attachments/assets/9996c1ca-c3ea-415c-ab2b-359d826a1ffa ## Summary by CodeRabbit - **Bug Fixes** - Improved handling of changes to child elements, ensuring more accurate updates when items are added or removed. This results in more reliable display and interaction with nested components. --- blocksuite/framework/std/src/gfx/layer.ts | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/blocksuite/framework/std/src/gfx/layer.ts b/blocksuite/framework/std/src/gfx/layer.ts index 239ed4cbf0..fe3259f0ab 100644 --- a/blocksuite/framework/std/src/gfx/layer.ts +++ b/blocksuite/framework/std/src/gfx/layer.ts @@ -825,7 +825,7 @@ export class LayerManager extends GfxExtension { const block = store.getModelById(payload.id); if (block instanceof GfxBlockElementModel) { - this.delete(block as GfxBlockElementModel); + this.delete(block); } } }) @@ -834,20 +834,29 @@ export class LayerManager extends GfxExtension { const watchSurface = (surface: SurfaceBlockModel) => { let lastChildMap = new Map(surface.childMap.peek()); this._disposable.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 = this._doc.getBlock(id); - if (block?.model) { - this.delete(block.model as GfxBlockElementModel); + const model = this._doc.getModelById(id); + if (model instanceof GfxBlockElementModel) { + this.delete(model); } }); - lastChildMap = new Map(val); + currentChildMap.forEach((_, id) => { + const model = store.getModelById(id); + if ( + model instanceof GfxBlockElementModel && + !this.blocks.includes(model) + ) { + this.add(model); + } + }); + lastChildMap = new Map(currentChildMap); }) );