From 398f5f18ed34e36c08eebba59fd43889fefa8453 Mon Sep 17 00:00:00 2001 From: David Mosbach Date: Sat, 26 Aug 2023 05:13:55 +0200 Subject: [PATCH] fixed deletion of edges connected to ghost nodes --- editor.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/editor.ts b/editor.ts index e41302f..9097b31 100644 --- a/editor.ts +++ b/editor.ts @@ -668,7 +668,7 @@ export function ghostEdgeFrom() { export function removeSelection() { if (selection) { - if (selection.hasOwnProperty('actionData')) removeAction(selection); + if (selection instanceof WF.WFEdge) removeAction(selection); else removeState(selection); deselect(); edgeTarget = rightSelection = null; @@ -678,7 +678,7 @@ export function removeSelection() { export function removeRightSelection() { if (rightSelection) { - if (rightSelection.hasOwnProperty('actionData')) removeAction(rightSelection); + if (rightSelection instanceof WF.WFEdge) removeAction(rightSelection); else removeState(rightSelection); if (selection === rightSelection) deselect(); edgeTarget = rightSelection = null; @@ -728,6 +728,10 @@ function generatePanelContent(selection: WF.WFNode | WF.WFEdge) { * @param action The action to remove. */ function removeAction(action: WF.WFEdge) { + if (action.source instanceof WF.WFGhostNode) + removeState(action.source); + if (action.target instanceof WF.WFGhostNode) + removeState(action.target); workflow.actions.splice(workflow.actions.indexOf(action), 1); actionIndex.remove(action.id); } @@ -738,11 +742,11 @@ function removeAction(action: WF.WFEdge) { * @param {*} state The state to remove. */ function removeState(state: WF.WFNode | WF.WFGhostNode) { - workflow.actions - .filter(edge => edge.source === state || edge.target === state) - .forEach(edge => removeAction(edge)); workflow.states.splice(workflow.states.indexOf(state), 1); if (state instanceof WF.WFNode) { + workflow.actions + .filter(edge => edge.source === state || edge.target === state) + .forEach(edge => removeAction(edge)); stateAbbreviations.splice(stateAbbreviations.indexOf(state.stateData.abbreviation), 1); nodeIndex.remove(state.id); }