Skip to content

Implement pasting nodes at cursor position in graph#4285

Open
kevlu93 wants to merge 3 commits into
GraphiteEditor:masterfrom
kevlu93:paste-node-cursor-position-in-graph
Open

Implement pasting nodes at cursor position in graph#4285
kevlu93 wants to merge 3 commits into
GraphiteEditor:masterfrom
kevlu93:paste-node-cursor-position-in-graph

Conversation

@kevlu93

@kevlu93 kevlu93 commented Jun 26, 2026

Copy link
Copy Markdown

Closes #3798

This PR implements cursor-based paste by calculating the offset of the first selected node to be copied from the location of the most recent click. The following changes were added:

  1. The copied nodes are sorted by new id, so that we know the selection order of the nodes.
  2. Calculate the difference between the mouse position (ipp.mouse.position) and the location of the first selected node.
  3. Add the nodes to the graph (NodeGraphMessage::AddNodes), and then shift by the offset (NodeGraphMessage::ShiftSelectedNodesByAmount)

One thing I'm not sure about is that one needs to actually click the desired paste location in order for ipp.mouse.position to update. Is there another something else tracking the cursor location?

Here's two examples of copy and paste

First we select the Transform node at (-15,3) as well as the Path node.

initial copy

Next, I click (-16,4) based on eyeballing the grid, then paste the nodes with Ctrl+v. The Transform node is pasted to (-16,4), while the pasted Path node maintains the relative distance to the Transform node, without any wires to the Transform node.

paste1

Next, I select Stroke -> Transform -> Path and then copy the nodes. Stroke is at (-22, 3).

second copy

Finally, I click at (-16, 8) then paste with Ctrl+v. We paste Stroke node at (-16, 8), and the other selected nodes are copied as well with wires maintained.

paste2

@kevlu93 kevlu93 marked this pull request as draft June 26, 2026 18:22

@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 implements pasting nodes at the cursor's position in the node graph by calculating the offset between the cursor and the first absolutely positioned node, then shifting the pasted nodes accordingly. The feedback suggests avoiding the hardcoded grid size of 24. in favor of using the GRID_SIZE constant, and simplifying the reference handling of IVec2 by copying the option value.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

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

@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 2 files

Confidence score: 5/5

  • In editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs, hardcoding 24. instead of GRID_SIZE can cause subtle grid alignment inconsistencies later if the shared constant changes, increasing maintenance risk rather than immediate runtime risk — replace the literal with GRID_SIZE as f64 before merging to keep behavior centralized.

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

Re-trigger cubic

Comment thread editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs Outdated
@kevlu93 kevlu93 marked this pull request as ready for review June 26, 2026 19:18
@kevlu93 kevlu93 changed the title Draft: Implement pasting nodes at cursor position in graph Implement pasting nodes at cursor position in graph Jun 26, 2026

@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 2 files

Confidence score: 5/5

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

Re-trigger cubic

@timon-schelling

timon-schelling commented Jun 26, 2026

Copy link
Copy Markdown
Member

!build (Run ID 28262192850)

@github-actions

Copy link
Copy Markdown
📦 Web Build Complete for a85b47a
https://8e70a706.graphite.pages.dev

Wasm: 23.14 MB — JS: 0.44 MB — CSS: 0.09 MB — Fonts: 0.30 MB — Images: 0.09 MB — All Assets: 24.07 MB

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.

Pasted node should spawn at cursor's position in the graph

2 participants