Custom click selecting tool behavior breaks doubleClick

Go.js ver 1.6.11

Using a mouse select tool without breaking double click.

So this worked in go.js 1.4, and I’m trying to figure out what changed so I can fix it.

I have a diagram with objects that can be duplicated, and I have a custom mouseSelect function to select the duplicates when one of them is selected:

    var tool = this.diagram.toolManager.clickSelectingTool;
    tool.standardMouseSelect = function() {
        var diagram = tool.diagram;
        var e = diagram.lastInput;
        var curObj = diagram.findPartAt(e.documentPoint, false);
        var partsToSelect = getDataNodesWithSameNameAsNode(curObj);
        if (partsToSelect.length > 0) {
            diagram.selectCollection(partsToSelect)
        } else {
            go.ClickSelectingTool.prototype.standardMouseSelect.call(tool);
        }
    };

However, this means that some objects aren’t getting doubleClick functions fired when they should. It seems like you have to have an object selected, then double click, in order to get the double click to fire (probably because then the canStart on the selection tool is returning false in that case?)

Is there a way for me to maintain this behavior but prevent the tool from affecting the doubleClick action? I tried to more or less copy the tool override design in the samples, but I might’ve missed one of the finer points while adapting the code.

I just tried your override code, unaltered. I had to add some stuff to get it to work:

    function getDataNodesWithSameNameAsNode(node) {
      var results = [];
      if (node) {
        myDiagram.nodes.each(function(n) { if (n.data.text === node.data.text) results.push(n); });
      }
      return results;
    }

    var tool = myDiagram.toolManager.clickSelectingTool;
    tool.standardMouseSelect = function() {
      var diagram = tool.diagram;
      var e = diagram.lastInput;
      var curObj = diagram.findPartAt(e.documentPoint, false);
      var partsToSelect = getDataNodesWithSameNameAsNode(curObj);
      if (partsToSelect.length > 0) {
        diagram.selectCollection(partsToSelect)
      } else {
        go.ClickSelectingTool.prototype.standardMouseSelect.call(tool);
      }
    };

    myDiagram.nodeTemplate =
      $(go.Node, "Auto",
        {
          doubleClick: function(e, node) { console.log("double-click on " + node.data.key); }
        },
        . . .);

This worked in both version 1.4.0 and in 1.8.15 (latest). It correctly selected multiple nodes with the same data.text property. It correctly handled double-clicks on such nodes.

So somehow I am missing what the problem is.

Hmm. I’m relatively sure the problem is in there somewhere, because if I remove the tool, everything works fine, and I’m never even getting to my code when the doubleClick fails to fire. I put breakpoints in the go.js code here:

        case 1:
            e = "ObjectSingleClicked";
            break;
        case 2:
            e = "ObjectDoubleClicked";
            break;
        case 3:
            e = "ObjectContextClicked"

and I can see that the double click isn’t firing the first time.

Can you try in 1.6.11 just to make sure it’s not something specific to that (I can’t imagine it would be, but I’d feel dumb for not checking if it was)?

My double clicks are all defined like so:

    getTaskNode: function () {
        return GO(go.Node, "Vertical",
            new go.Binding("location", "", getLocation),
            {
                selectionAdorned: false,
                background: "transparent",
                doubleClick: handleDoubleClickTaskNode,
                contextClick: showContextMenu,
                mouseEnter: loadTaskTooltip,
                toolTip: buildTaskTooltip()
            },
            // the main content:
            GO(go.Panel, "Auto",
                {
                    background: "transparent"
                },
                node stuff here
            )
        );
    },

I have put breakpoints in the handleDoubleClickTaskNode code and it never reaches it on that initial double click.

Could it be relevant that the double click on the nodes that function is intended to select work, but it’s other diagram nodes that don’t. There are tasks and data objects. That code is intended to select multiple data objects, and double click works fine on data objects, however it doesn’t work on tasks.

Edit: Maybe I should remove that tool and just write a custom click function to put on the data object template…

OK, I just tried using 1.6.11. Same behavior.

You can easily try different versions just by getting the library from Page Not Found -- Northwoods Software where:

  1. M is the major version number (must be 1, for now)
  2. N is the minor version number
  3. B is the base level or bug fix number

So changing the code from that custom click select tool, to this bound to ‘click’:

function handleSingleClickDataNode(e, node) {
    var partsToSelect = getDataNodesWithSameNameAsNode(node);
    if (partsToSelect.length > 0) {
        node.diagram.selectCollection(partsToSelect);
    }
}

makes it work fine. Not sure what’s up with it, but I guess it works now.