Skip to content

Commit 7a6e4f6

Browse files
authored
Fix new nodes being added in the wrong place near graph edges (#4211)
1 parent b645871 commit 7a6e4f6

3 files changed

Lines changed: 7 additions & 2 deletions

File tree

editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
876876

877877
self.context_menu = Some(ContextMenuInformation {
878878
context_menu_coordinates: (node_graph_point + node_graph_shift).as_ivec2().into(),
879+
node_creation_coordinates: node_graph_point.as_ivec2().into(),
879880
context_menu_data,
880881
});
881882

@@ -1315,6 +1316,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
13151316

13161317
self.context_menu = Some(ContextMenuInformation {
13171318
context_menu_coordinates: (point + node_graph_shift).as_ivec2().into(),
1319+
node_creation_coordinates: point.as_ivec2().into(),
13181320
context_menu_data: ContextMenuData::CreateNode { compatible_type },
13191321
});
13201322

editor/src/messages/portfolio/document/node_graph/utility_types.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,12 @@ pub enum ContextMenuData {
162162
#[cfg_attr(feature = "wasm", derive(tsify::Tsify))]
163163
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
164164
pub struct ContextMenuInformation {
165-
// Stores whether the context menu is open and its position in graph coordinates
165+
// The menu's display position in graph coordinates, which may be shifted from the click point to keep the menu on-screen
166166
#[serde(rename = "contextMenuCoordinates")]
167167
pub context_menu_coordinates: (i32, i32),
168+
// The click point in graph coordinates, where a node created from the menu is placed (unshifted, unlike the display position)
169+
#[serde(rename = "nodeCreationCoordinates")]
170+
pub node_creation_coordinates: (i32, i32),
168171
#[serde(rename = "contextMenuData")]
169172
pub context_menu_data: ContextMenuData,
170173
}

frontend/src/components/views/Graph.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
function createNode(identifier: string) {
140140
if ($nodeGraph.contextMenuInformation === undefined) return;
141141
142-
editor.createNode(identifier, $nodeGraph.contextMenuInformation.contextMenuCoordinates[0], $nodeGraph.contextMenuInformation.contextMenuCoordinates[1]);
142+
editor.createNode(identifier, $nodeGraph.contextMenuInformation.nodeCreationCoordinates[0], $nodeGraph.contextMenuInformation.nodeCreationCoordinates[1]);
143143
}
144144
145145
function nodeBorderMask(nodeWidth: number, primaryInputExists: boolean, exposedSecondaryInputs: number, primaryOutputExists: boolean, exposedSecondaryOutputs: number): string {

0 commit comments

Comments
 (0)