From 159324728fc97a4a57318fe06fff58d306971d21 Mon Sep 17 00:00:00 2001 From: larrytzhang Date: Wed, 10 Apr 2024 20:23:25 +0800 Subject: [PATCH] fix: delete connection error --- src/presets/classic/index.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/presets/classic/index.ts b/src/presets/classic/index.ts index 6fc81ea..c382679 100644 --- a/src/presets/classic/index.ts +++ b/src/presets/classic/index.ts @@ -32,14 +32,19 @@ export function setup(nodes: ItemDefinition[] key: 'delete', async handler() { const nodeId = context.id - const connections = editor.getConnections().filter(c => { - return c.source === nodeId || c.target === nodeId - }) - for (const connection of connections) { - await editor.removeConnection(connection.id) + if (editor.getConnection(nodeId)) { + editor.removeConnection(nodeId) + } else { + const connections = editor.getConnections().filter(c => { + return c.source === nodeId || c.target === nodeId + }) + + for (const connection of connections) { + await editor.removeConnection(connection.id) + } + await editor.removeNode(nodeId) } - await editor.removeNode(nodeId) } }