Copying link data when link is copied using LocalStorageCommandHandler

I am using the LocalStorageCommandHandler so that I can copy parts between tabs; however, the links lose all their data. For example, the name (i.e. text) for the link and the arrow heads default to the original instead of what the copied version was. I noticed that the data is still there all the way up until copymap in the code below, but disappears when adding all the information to the set. Is there a way to keep the data on copy/paste?

    LocalStorageCommandHandler.prototype.pasteFromClipboard = function() {
        var coll = new go.Set(/*go.Part*/);
        try {
            var diagram = allDiagrams[0];
            var clipstr = window.localStorage.getItem(this.StorageKey);
            var clipfrmt = window.localStorage.getItem(this.FormatKey);
            if (clipstr === null || clipstr === '' || clipfrmt !== diagram.model.dataFormat) {
                return coll;
            } else {
                var clipdiag = new go.Diagram();  // create a temporary Diagram

                // recover the model from the clipboard rendering
                clipdiag.model = go.Model.fromJson(clipstr);

                // copy all the CLIPDIAG Parts into this Diagram
                var all = new go.List().addAll(clipdiag.parts).addAll(clipdiag.nodes).addAll(clipdiag.links);
                var copymap = diagram.copyParts(all, diagram, false);

                // return a Set of the copied Parts
                console.log(new go.Set(/*go.Part*/).addAll(copymap.iteratorValues));
                return new go.Set(/*go.Part*/).addAll(copymap.iteratorValues);
            }
        } catch (ex) {

            // fallback implementation
            return go.CommandHandler.prototype.pasteFromClipboard.call(this);
        }
    };

This is an example of what it is currently doing. The top is the original and the bottom is the copy:

So the desired data properties are present in clipstr, but not in the target model? That’s odd.

Just for fun, I modified the extensions/LocalStorageCommandHandler.html sample to use a link template like:

    myDiagram.linkTemplate =
      $(go.Link,
        $(go.Shape),
        $(go.Shape, { toArrow: "Standard" },
          new go.Binding("toArrow").makeTwoWay()),
        $(go.TextBlock, { editable: true },
          new go.Binding("text").makeTwoWay())
      );

    myDiagram2.linkTemplate = myDiagram.linkTemplate;

When I edited the text and then copy-pasted between diagrams, the link label text was copied correctly.

Yes, the desired data is there during clipstr:

It appears the data is lost on copyParts on this line:
var copymap = diagram.copyParts(all, diagram, false);

When I check what is in all I get:

all.iterator.each(function (part) {
    console.log(part.data)
})

…but copymap and the set produces the default values:

var test = new go.Set(/*go.Part*/).addAll(copymap.iteratorValues);
copymap.iteratorValues.iterator.each(function (part) {
    console.log(part.data)
})
test.iterator.each(function (part) {
    console.log(part.data)
})

… and get the following output:

I just tried it again and was unable to reproduce any problem. How can I reproduce the problem? How is your model defined? I’m wondering if there’s some customization of how GraphLinksModel.copyLinkData is operating.

BTW, an unrelated suggestion: you are using .iterator unnecessarily. Not that that would change the results that you are seeing.

You were right. I had some code that changed this on model change. Thanks for pointing me in the right direction.