Issue with copy & paste


#1

When we copy whole diagram & paste it is pasted where we want to paste it & paste it works fine.

When we copy a part of the diagram & paste it is not pasted desire place it is override the previous part.

How to fix this?

Please help.


#2

How are you invoking the paste command? Is it the same way both times?


#3

Yes same way both time.


#4

But how? You did not answer my first question.


#5

myDiagram =
$(go.Diagram, “myDiagramDiv”, {
“ClipboardPasted”:ClipboardPasted,
});

function ClipboardPasted(e){

}


#6

Is the user typing Ctrl-V? What does ClipboardPasted do?


#7

Yes.
When press Ctrl-V the following code is executed.
myDiagram.commandHandler.pasteSelection(myDiagram.lastInput.documentPoint);


#8

So where the pasted copied parts go depends on where the mouse last was. Does that answer your question?

What does ClipboardPasted do?


#9

This function change node data name, key, etc .


#10

But that listener does not move the nodes? So that function doesn’t actually matter to your question. OK.

In any case you seem to have answered your question by explaining how CommandHandler.pasteSelection is being called.


#11

Let me explain again.
Let two nodes (Node 1 & Node 2) and one link (Link 1) are there.
When we copy Node 1 Or Node 2 and paste it, it works fine. Pasting where we point the mouse.

But when we copy (Node 1 And Link 1 ) Or (Node 2 And Link 1) and paste it. Pasting is override the copy node.

Can you tell me how to resolve this?
We are copy using Ctrl-C And Ctrl-v.
For Ctrl-C our code is myDiagram.commandHandler.copySelection();
for Ctrl-v our code is myDiagram.commandHandler.pasteSelection(myDiagram.lastInput.documentPoint);


#12

OK, I just tried this, and I did not have any trouble – the custom paste always inserted the node(s) at the current mouse point.

    $(go.Diagram, . . .,
      { . . .,
        "commandHandler.doKeyDown": function() {
          var e = this.diagram.lastInput;
          if (e.control && e.key === "F") {
            this.pasteSelection(e.documentPoint);
          } else {
            go.CommandHandler.prototype.doKeyDown.call(this);
          }
       }
    })

Here I bound the Ctrl-F keyboard command so that I could continue testing Ctrl-V as well.