Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
fix: delete the connection the user clicks on
Browse files Browse the repository at this point in the history
  • Loading branch information
prescientmoon committed Jul 9, 2020
1 parent 3466e25 commit cf58c65
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/Component/Editor.purs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ component =
RemoveConnection id index -> do
modify_ $ removeConnection $ Tuple id index
void updateAll
printString $ "Removed " <> show id <> " w index " <> show index
handleAction Rerender
SetRuntimeValue functionName nodeId runtimeValue -> do
modify_ $ setRuntimeValue functionName nodeId runtimeValue
Expand Down
8 changes: 5 additions & 3 deletions src/Data/Editor/State.purs
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,11 @@ initializeFunction name state =

-- Remove a conenction from the current function
removeConnection :: forall a s m. Tuple NodeId Int -> State a s m -> State a s m
removeConnection (Tuple toId toIndex) state = compile state'
where
state' = set (_atCurrentNode toId <<< _nodeInput toIndex) Nothing state
removeConnection (Tuple toId toIndex) =
execState
$ withCurrentFunction_ \currentFunction -> do
modify_ $ set (_atNode currentFunction toId <<< _Just <<< _nodeInput toIndex) Nothing
modify_ compile

-- Deletes a node form a given function
deleteNode :: forall a s m. FunctionName -> NodeId -> State a s m -> State a s m
Expand Down
22 changes: 13 additions & 9 deletions src/typescript/target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,19 @@ export const getMouseTarget = (
(a, b) => distanceToMouse(a.closest) < distanceToMouse(b.closest),
nodes.flatMap(([id, node]) =>
node.inputs[0].attribs?.selectable
? node.connections
.filter((connection) => connection.attribs!.connected)
.map((connection, index) => ({
index,
node,
id,
closest: closestPoint(connection, mousePosition)!,
geom: connection
}))
? node.connections.flatMap((connection, index) =>
connection.attribs!.connected
? [
{
index,
node,
id,
closest: closestPoint(connection, mousePosition)!,
geom: connection
}
]
: []
)
: []
)
)
Expand Down

0 comments on commit cf58c65

Please sign in to comment.