Exclude certain objects in Drag Selecting Tool


#1

How would I go about excluding certain objects when the user double-clicks and drags a box to select objects? I don’t want to make those objects unselectable when the user clicks on them normally.


#2

You could try overriding DragSelectingTool.selectInRect.

$(go.Diagram, . . .,
        {
          initialContentAlignment: go.Spot.Center,  // center the content
          "dragSelectingTool.selectInRect": function(rect) {
             go.DragSelectingTool.prototype.selectInRect.call(this, rect);
             this.diagram.selection.copy().each(function(part) {
               if (part instanceof go.Node && part.data.key.indexOf("e") > 0) {
                  part.isSelected = false;
                }
              })
          },

Note that the override calls the standard implementation and then sees if it selected some Node that perhaps it should not have. In this case the criteria is whether the node’s key includes the letter “e”.