Skip to content

Auto create Read node when inserting Map node into chain (#4792) - #4819

Closed
shubhtrek wants to merge 1 commit into
GraphiteEditor:masterfrom
shubhtrek:auto-create-read-node-for-map
Closed

shubhtrek wants to merge 1 commit into
GraphiteEditor:masterfrom
shubhtrek:auto-create-read-node-for-map

Conversation

@shubhtrek

Copy link
Copy Markdown
Contributor

Fixes #4792

Description

When a Map node is added to a chain or inserted into an existing wire, it now checks the type of data coming into its content input and automatically adds the matching Read node to the mapped input.

It supports Vector, Graphic, Raster (CPU), Color, Gradient, Number, and String types.

The Read node is placed to the left of the Map node. If the mapped input is already connected, the existing connection is left unchanged.

Tests

Added a test to check that inserting a Map node automatically creates the correct Read node.
Added a test to make sure an existing mapped connection is preserved.

…tor#4792)

When splicing a Map node onto a wire or inserting it into a chain, inspect the upstream element type and automatically instantiate and wire the corresponding Read node into the mapped input. If input 1 is already connected, preserve existing wiring.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 2 files

Confidence score: 3/5

  • In layout.rs, the connection guard treats only NodeInput::Node as connected, so create_wire can replace a mapped import with an auto-created Read node in a nested network. Treat NodeInput::Import as connected too.
  • move_node_to_chain_start skips the helper when Map is first in a chain and on the import path, leaving Map without its required Read node. Call the helper on both paths.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="editor/src/messages/portfolio/document/utility_types/network_interface/layout.rs">

<violation number="1" location="editor/src/messages/portfolio/document/utility_types/network_interface/layout.rs:1163">
P1: `move_node_to_chain_start` skips this helper when Map is added as the first node in a chain, and also on its `import` path. Those direct wiring paths leave the Map without the required Read node; invoke the helper after those wirings as well.</violation>

<violation number="2" location="editor/src/messages/portfolio/document/utility_types/network_interface/layout.rs:1173">
P1: `NodeInput::Import` is a real wire connection, but this guard only treats `NodeInput::Node` as connected. In a nested network, the later `create_wire` replaces an existing mapped import with an auto-created Read node; preserve imports in this guard.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

}

let mapped_input_connector = InputConnector::node_at_index(*node_id, 1);
if matches!(self.input_from_connector(&mapped_input_connector, network_path), Some(NodeInput::Node { .. })) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: NodeInput::Import is a real wire connection, but this guard only treats NodeInput::Node as connected. In a nested network, the later create_wire replaces an existing mapped import with an auto-created Read node; preserve imports in this guard.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At editor/src/messages/portfolio/document/utility_types/network_interface/layout.rs, line 1173:

<comment>`NodeInput::Import` is a real wire connection, but this guard only treats `NodeInput::Node` as connected. In a nested network, the later `create_wire` replaces an existing mapped import with an auto-created Read node; preserve imports in this guard.</comment>

<file context>
@@ -1154,6 +1154,61 @@ impl NodeNetworkInterface {
+		}
+
+		let mapped_input_connector = InputConnector::node_at_index(*node_id, 1);
+		if matches!(self.input_from_connector(&mapped_input_connector, network_path), Some(NodeInput::Node { .. })) {
+			return;
+		}
</file context>
Suggested change
if matches!(self.input_from_connector(&mapped_input_connector, network_path), Some(NodeInput::Node { .. })) {
if matches!(self.input_from_connector(&mapped_input_connector, network_path), Some(NodeInput::Node { .. } | NodeInput::Import { .. })) {


/// If `node_id` is a Map node whose "Mapped" input (index 1) is unconnected, inspects the type feeding its primary
/// input (index 0) and creates a matching "Read X" node wired into the "Mapped" input.
pub fn auto_create_read_node_for_map(&mut self, node_id: &NodeId, network_path: &[NodeId]) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: move_node_to_chain_start skips this helper when Map is added as the first node in a chain, and also on its import path. Those direct wiring paths leave the Map without the required Read node; invoke the helper after those wirings as well.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At editor/src/messages/portfolio/document/utility_types/network_interface/layout.rs, line 1163:

<comment>`move_node_to_chain_start` skips this helper when Map is added as the first node in a chain, and also on its `import` path. Those direct wiring paths leave the Map without the required Read node; invoke the helper after those wirings as well.</comment>

<file context>
@@ -1154,6 +1154,61 @@ impl NodeNetworkInterface {
+
+	/// If `node_id` is a Map node whose "Mapped" input (index 1) is unconnected, inspects the type feeding its primary
+	/// input (index 0) and creates a matching "Read X" node wired into the "Mapped" input.
+	pub fn auto_create_read_node_for_map(&mut self, node_id: &NodeId, network_path: &[NodeId]) {
+		let is_map_node = matches!(
+			self.implementation(node_id, network_path),
</file context>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auto create Read x node when inserting map node into chain

1 participant