From 747dae3bb68435246efc9b55c1c6fc0a95c74ce7 Mon Sep 17 00:00:00 2001 From: Keavon Chambers Date: Thu, 7 Dec 2023 16:17:25 -0800 Subject: [PATCH] Improve auto-linking of layers dragged onto links --- frontend/src/components/panels/Document.svelte | 2 ++ frontend/src/components/views/Graph.svelte | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/panels/Document.svelte b/frontend/src/components/panels/Document.svelte index b1ec18bc..b23804ed 100644 --- a/frontend/src/components/panels/Document.svelte +++ b/frontend/src/components/panels/Document.svelte @@ -589,6 +589,8 @@ .shelf { flex: 0 0 auto; justify-content: space-between; + // A precaution in case the variables above somehow fail + max-width: calc(32px * 3); .tools { flex: 0 1 auto; diff --git a/frontend/src/components/views/Graph.svelte b/frontend/src/components/views/Graph.svelte index 5de9c63b..12520d65 100644 --- a/frontend/src/components/views/Graph.svelte +++ b/frontend/src/components/views/Graph.svelte @@ -466,7 +466,7 @@ const theNodesContainer = nodesContainer; // Find the link that the node has been dragged on top of - const link = $nodeGraph.links.find((link): boolean => { + const link = $nodeGraph.links.find((link) => { const { nodeInput, nodeOutput } = resolveLink(link); if (!nodeInput || !nodeOutput) return false; @@ -487,9 +487,11 @@ // If the node has been dragged on top of the link then connect it into the middle. if (link) { - editor.instance.connectNodesByLink(link.linkStart, 0, selectedNodeId, 0); + const isLayer = $nodeGraph.nodes.find((node) => node.id === selectedNodeId)?.isLayer; + + editor.instance.connectNodesByLink(link.linkStart, 0, selectedNodeId, isLayer ? 1 : 0); editor.instance.connectNodesByLink(selectedNodeId, 0, link.linkEnd, Number(link.linkEndInputIndex)); - editor.instance.shiftNode(selectedNodeId); + if (!isLayer) editor.instance.shiftNode(selectedNodeId); } } function pointerUp(e: PointerEvent) {