From 54df65951b6cbf69b97847089daca22b0ca4b886 Mon Sep 17 00:00:00 2001 From: "kelin.zrh" Date: Thu, 22 Feb 2024 19:40:07 +0800 Subject: [PATCH 1/2] fix: issue #2632 --- src/components/block/index.ts | 2 +- src/components/modules/blockManager.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/components/block/index.ts b/src/components/block/index.ts index 493f9657c..1cb96a4c0 100644 --- a/src/components/block/index.ts +++ b/src/components/block/index.ts @@ -528,7 +528,7 @@ export default class Block extends EventsDispatcher { try { // eslint-disable-next-line no-useless-call - this.toolInstance[methodName].call(this.toolInstance, params); + return this.toolInstance[methodName].call(this.toolInstance, params); } catch (e) { _.log(`Error during '${methodName}' call: ${e.message}`, 'error'); } diff --git a/src/components/modules/blockManager.ts b/src/components/modules/blockManager.ts index ae8e4818c..db2eb1a3b 100644 --- a/src/components/modules/blockManager.ts +++ b/src/components/modules/blockManager.ts @@ -546,6 +546,14 @@ export default class BlockManager extends Module { continue; } + /** + * prevent deletion if return -1 + */ + const ret: any = this.blocks[index].call('beforeDestroy'); + if (ret === -1) { + continue; + } + this.removeBlock(this.blocks[index]); firstSelectedBlockIndex = index; } From cec62257feb720a26b0d9e83214a42f2227f621f Mon Sep 17 00:00:00 2001 From: "kelin.zrh" Date: Fri, 23 Feb 2024 07:21:24 +0800 Subject: [PATCH 2/2] feat: rename to beforeSelectedDestroy --- src/components/modules/blockManager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/modules/blockManager.ts b/src/components/modules/blockManager.ts index db2eb1a3b..8d752c0f4 100644 --- a/src/components/modules/blockManager.ts +++ b/src/components/modules/blockManager.ts @@ -549,7 +549,7 @@ export default class BlockManager extends Module { /** * prevent deletion if return -1 */ - const ret: any = this.blocks[index].call('beforeDestroy'); + const ret: any = this.blocks[index].call('beforeSelectedDestroy'); if (ret === -1) { continue; }