Skip to content

Fix Alt-drag duplicate cleanup on right-click abort#3782

Open
jsjgdh wants to merge 10 commits into
GraphiteEditor:masterfrom
jsjgdh:Alt-Fix
Open

Fix Alt-drag duplicate cleanup on right-click abort#3782
jsjgdh wants to merge 10 commits into
GraphiteEditor:masterfrom
jsjgdh:Alt-Fix

Conversation

@jsjgdh

@jsjgdh jsjgdh commented Feb 17, 2026

Copy link
Copy Markdown
Contributor

@jsjgdh jsjgdh marked this pull request as draft February 17, 2026 23:16
@Keavon

Keavon commented Feb 17, 2026

Copy link
Copy Markdown
Member

/gemini review

Copilot AI 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.

Pull request overview

This PR aims to ensure Alt-drag node duplication is cleaned up correctly when the drag is aborted (notably via right-click), by tracking whether duplication occurred during the drag and adjusting transaction handling.

Changes:

  • Introduces a duplicated_in_drag flag to track Alt-drag duplication state across drag lifecycle.
  • Splits duplication into a regular path vs. an Alt-drag path (DuplicateSelectedNodesForDrag) via a shared helper implementation.
  • Adjusts abort/commit behavior on right-click/Escape/PointerUp to try to undo or finalize Alt-drag duplication.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.

File Description
editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs Adds duplicated_in_drag, introduces DuplicateSelectedNodesForDrag, and changes duplication + drag abort/commit behavior
editor/src/messages/portfolio/document/node_graph/node_graph_message.rs Adds the DuplicateSelectedNodesForDrag message variant
editor/src/messages/portfolio/document/document_message_handler.rs Changes Escape handling to attempt undoing Alt-drag duplication on abort

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs Outdated
Comment thread editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs Outdated
Comment thread editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs Outdated
Comment thread editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs Outdated
Comment thread editor/src/messages/portfolio/document/document_message_handler.rs Outdated
Comment thread editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs Outdated
Comment thread editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs Outdated

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request addresses an issue with cleaning up duplicated nodes when an Alt-drag operation is aborted. The changes introduce a duplicated_in_drag flag to track when a duplication has occurred during a drag, and uses this flag to ensure proper cleanup via transaction abortion and undos. The logic has been updated for both Escape key and right-click aborts. A good refactoring was done to extract the node duplication logic into a shared duplicate_selected_nodes_impl function.

I have one suggestion to improve code clarity by removing a redundant if/else block. Overall, the changes look good and correctly solve the issue.

Comment thread editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs Outdated
Comment thread editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs Outdated
@Keavon Keavon force-pushed the master branch 4 times, most recently from 3697b7d to 90533e6 Compare March 11, 2026 12:15
@jsjgdh jsjgdh marked this pull request as ready for review March 13, 2026 14:31

@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.

1 issue found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs">

<violation number="1" location="editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs:1134">
P2: Alt-drag duplicates are now created inside the current drag transaction (no AddTransaction), but ShakeNode still aborts that transaction mid-drag to reset state. This rollback now deletes the duplicate itself, so Alt-drag followed by Shake loses the duplicated nodes and leaves shake logic operating on the pre-duplication selection. The new duplicated_in_drag flag is never used to guard this path.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs Outdated
@Keavon Keavon force-pushed the master branch 7 times, most recently from 9b97ab7 to 2e842cb Compare March 19, 2026 11:00
@Keavon Keavon force-pushed the master branch 2 times, most recently from f07c79b to 76938eb Compare April 29, 2026 12:16
@Keavon Keavon force-pushed the master branch 2 times, most recently from 4b7a823 to 847b8e9 Compare May 17, 2026 14:37
@timon-schelling timon-schelling force-pushed the master branch 2 times, most recently from 15fcaac to d5f0140 Compare May 17, 2026 15:37
@jsjgdh

jsjgdh commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

@cubic-dev

@cubic-dev-ai

cubic-dev-ai Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev

@jsjgdh I have started the AI code review. It will take a few minutes to complete.

@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.

No issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@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.

1 issue found across 3 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs">

<violation number="1">
P2: The core node-copy logic (computing `all_selected_nodes`, `copy_ids`, `copy_nodes`, `new_ids`, then sending `AddNodes` + `SelectedNodesSet`) is now duplicated in two places: the `DuplicateSelectedNodes` message handler and the Alt-drag path inside `PointerDown`. Previously this was centralized in `duplicate_selected_nodes_impl`. While the transaction setup differs (`AddTransaction` in one path, none in the other because it runs inside an existing transaction), the four computation lines and the two response messages are identical. Extracting just the shared computation (mapping, copy, ID generation) into a private helper would prevent these two paths from drifting apart.</violation>
</file>

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

@@ -1172,7 +1172,17 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
if self.begin_dragging {

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.

P2: The core node-copy logic (computing all_selected_nodes, copy_ids, copy_nodes, new_ids, then sending AddNodes + SelectedNodesSet) is now duplicated in two places: the DuplicateSelectedNodes message handler and the Alt-drag path inside PointerDown. Previously this was centralized in duplicate_selected_nodes_impl. While the transaction setup differs (AddTransaction in one path, none in the other because it runs inside an existing transaction), the four computation lines and the two response messages are identical. Extracting just the shared computation (mapping, copy, ID generation) into a private helper would prevent these two paths from drifting apart.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs, line 398:

<comment>The core node-copy logic (computing `all_selected_nodes`, `copy_ids`, `copy_nodes`, `new_ids`, then sending `AddNodes` + `SelectedNodesSet`) is now duplicated in two places: the `DuplicateSelectedNodes` message handler and the Alt-drag path inside `PointerDown`. Previously this was centralized in `duplicate_selected_nodes_impl`. While the transaction setup differs (`AddTransaction` in one path, none in the other because it runs inside an existing transaction), the four computation lines and the two response messages are identical. Extracting just the shared computation (mapping, copy, ID generation) into a private helper would prevent these two paths from drifting apart.</comment>

<file context>
@@ -397,13 +395,19 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
-				self.duplicate_selected_nodes_impl(network_interface, selection_network_path, responses, false);
-				responses.add(DocumentMessage::EndTransaction);
-				responses.add(DocumentMessage::StartTransaction);
+				let all_selected_nodes = network_interface.upstream_chain_nodes(selection_network_path);
+
+				let copy_ids = all_selected_nodes.iter().enumerate().map(|(new, id)| (*id, NodeId(new as u64))).collect::<HashMap<NodeId, NodeId>>();
</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.

3 participants