So I’m following this to offset copy & paste so the nodes aren’t on top of each other.
https://gojs.net/latest/extensions/DrawCommandHandler.js
When I make the call to Point.add() it actually modifies both points so each paste doubles the offset from the previous paste. Here is my code with some console.logs() in it.
onPasteFromClipboard = scope => {
const { pasteOffset, lastPasteOffset } = this.state;
const parts = go.CommandHandler.prototype.pasteFromClipboard.call(scope);
console.log(`before pasteOffset ${JSON.stringify(pasteOffset)}`);
console.log(`before lastPasteOffset ${JSON.stringify(lastPasteOffset)}`);
scope.diagram.moveParts(parts, lastPasteOffset);
this.setState({ lastPasteOffset: lastPasteOffset.add(pasteOffset) });
console.log(`after pasteOffset ${JSON.stringify(pasteOffset)}`);
console.log(`after lastPasteOffset ${JSON.stringify(lastPasteOffset)}`);
return parts;
};
I do a single copy then multiple pastes and here is the console output.
before pasteOffset {"x":90,"y":90}
before lastPasteOffset {"x":90,"y":90}
after pasteOffset {"x":180,"y":180}
after lastPasteOffset {"x":180,"y":180}
before pasteOffset {"x":180,"y":180}
before lastPasteOffset {"x":180,"y":180}
after pasteOffset {"x":360,"y":360}
after lastPasteOffset {"x":360,"y":360}
before pasteOffset {"x":360,"y":360}
before lastPasteOffset {"x":360,"y":360}
after pasteOffset {"x":720,"y":720}
after lastPasteOffset {"x":720,"y":720}
So it appears looking at the output that lastPasteOffset.add(pasteOffset) is modifying both lastPasteOffset and pasteOffset. Should it be doing this?