Fix new nodes being added in the wrong place near graph edges (#4211)

This commit is contained in:
Keavon Chambers
2026-06-07 19:22:30 -07:00
committed by GitHub
parent b645871dbc
commit 7a6e4f6f25
3 changed files with 7 additions and 2 deletions

View File

@@ -876,6 +876,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
self.context_menu = Some(ContextMenuInformation {
context_menu_coordinates: (node_graph_point + node_graph_shift).as_ivec2().into(),
node_creation_coordinates: node_graph_point.as_ivec2().into(),
context_menu_data,
});
@@ -1315,6 +1316,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
self.context_menu = Some(ContextMenuInformation {
context_menu_coordinates: (point + node_graph_shift).as_ivec2().into(),
node_creation_coordinates: point.as_ivec2().into(),
context_menu_data: ContextMenuData::CreateNode { compatible_type },
});

View File

@@ -162,9 +162,12 @@ pub enum ContextMenuData {
#[cfg_attr(feature = "wasm", derive(tsify::Tsify))]
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct ContextMenuInformation {
// Stores whether the context menu is open and its position in graph coordinates
// The menu's display position in graph coordinates, which may be shifted from the click point to keep the menu on-screen
#[serde(rename = "contextMenuCoordinates")]
pub context_menu_coordinates: (i32, i32),
// The click point in graph coordinates, where a node created from the menu is placed (unshifted, unlike the display position)
#[serde(rename = "nodeCreationCoordinates")]
pub node_creation_coordinates: (i32, i32),
#[serde(rename = "contextMenuData")]
pub context_menu_data: ContextMenuData,
}

View File

@@ -139,7 +139,7 @@
function createNode(identifier: string) {
if ($nodeGraph.contextMenuInformation === undefined) return;
editor.createNode(identifier, $nodeGraph.contextMenuInformation.contextMenuCoordinates[0], $nodeGraph.contextMenuInformation.contextMenuCoordinates[1]);
editor.createNode(identifier, $nodeGraph.contextMenuInformation.nodeCreationCoordinates[0], $nodeGraph.contextMenuInformation.nodeCreationCoordinates[1]);
}
function nodeBorderMask(nodeWidth: number, primaryInputExists: boolean, exposedSecondaryInputs: number, primaryOutputExists: boolean, exposedSecondaryOutputs: number): string {