From 8cf887d91f85b0a1ccd643fc5931b544b68952ca Mon Sep 17 00:00:00 2001 From: ma haidong <13501108114@163.com> Date: Sun, 17 Mar 2024 13:38:43 +0800 Subject: [PATCH] fix: delete connection error --- src/presets/classic/index.ts | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/presets/classic/index.ts b/src/presets/classic/index.ts index 6fc81ea..010456a 100644 --- a/src/presets/classic/index.ts +++ b/src/presets/classic/index.ts @@ -31,15 +31,23 @@ export function setup(nodes: ItemDefinition[] label: 'Delete', key: 'delete', async handler() { - const nodeId = context.id - const connections = editor.getConnections().filter(c => { - return c.source === nodeId || c.target === nodeId - }) + if ('source' in context && 'target' in context) { + // connection + const connectionId = context.id - for (const connection of connections) { - await editor.removeConnection(connection.id) + await editor.removeConnection(connectionId) + } else { + // node + 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) + } + await editor.removeNode(nodeId) } - await editor.removeNode(nodeId) } }