Implement pasting nodes at cursor position in graph

Closed
KE
1mo ago
+143-4

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