Clipboard support in multiple diagrams

Hi

Our application consists of a document that can contain multiple diagrams. We are using a single GoJS instance that we reload with different diagram model data as the user navigates the document. We are currently trying to implement clipboard support. This works within a single diagram but we are getting some strange behaviour when we try to copy from a diagram, move to another diagram and paste there. Before I investigate too much, could you confirm whether you’d expect this to work? Does the clipboard survive when a diagram has all of its model data replaced?

So you are keeping the same HTML DIV and associated go.Diagram, and are just replacing the Diagram.model? Is each model basically the same, but with different nodeDataArray (and linkDataArray if using GraphLinksModel)?

That should work. For example, if you go to http://gojs.net/latest/samples/stateChart.html, you can “Save” a diagram, delete everything and create some new stuff, select some or all of the new stuff and ^C copy that to the clipboard, “Load” the original diagram, and then ^V paste the new stuff from the clipboard.

The clipboard state is basically just a global variable in (JavaScript) memory. So if the page is reloaded, the state is lost. If you want it to have a longer lifetime, you can override CommandHandler.copyToClipboard and pasteFromClipboard to save the clipboard state wherever you’d like.

Yes, the example does what we’re trying to achieve. I imagine the problem is in our code somewhere. Is it possible to access the clipboard data used in the standard implementation or do we have to re-implement all the clipboard functions?

If you want to do something different than what is implemented by CommandHandler, just implement overrides of the two methods copyToClipboard and pasteFromClipboard. Whether you call the base method (i.e. use the standard functionality) or not is up to you.