RealTimeDragSelectionTool ignore some parts of a go.Node


We have a go.Node definition with some shapes, ports and textblocks (this are outside the shapes, like a label)
When we select with the drag tool we want that only the shape to be selected, we made in the go.Node selectableObject to be the shape not the text.
What we want when we do the drag selection, to the textblocks be ignored in the selection. So the isPartialInclusion attribute don’t really work for us, with false we have the drag to the textblocks too, with true if you drag to the text all node get selected. We want something in between (in this case ignore the textblocks) How can this be achevied?


Use this customized DragSelectingTool.selectInRect method:

    myDiagram.toolManager.dragSelectingTool.selectInRect = function(r) {
        var diagram = this.diagram;
        if (diagram === null) return;
        var e = diagram.lastInput;

        var parts = diagram.findObjectsIn(r,
          function(p) {
            var part = p.part;
            var selobj = part.selectionObject;
            if (p === selobj || p.isContainedBy(selobj) || part instanceof go.Link) return part;
            return null;
          function(p) { return p.canSelect(); },

        if (e.meta || e.control) {  // toggle or deselect
          if (e.shift) {  // deselect only
            var it = parts.iterator;
            while ( {
              var p = it.value;
              if (p.isSelected) p.isSelected = false;
          } else {  // toggle selectedness of parts
            var it = parts.iterator;
            while ( {
              var tp = it.value;
              tp.isSelected = !tp.isSelected;
        } else if (e.shift) {  // extend selection only
          var it = parts.iterator;
          while ( {
            var ep = it.value;
            if (!ep.isSelected) ep.isSelected = true;
        } else {  // select parts, and unselect all other previously selected parts
          // this tries to avoid deselecting and then reselecting any Part
          var tounselect = new go.List(go.Part);
          var sit = diagram.selection.iterator;
          while ( {
            var sp = sit.value;
            if (!parts.contains(sp)) tounselect.add(sp);
          var uit = tounselect.iterator;
          while ( {
            var up = uit.value;
            up.isSelected = false;
          var it = parts.iterator;
          while ( {
            var ps = it.value;
            if (!ps.isSelected) ps.isSelected = true;

I believe you will also want to set DragSelectingTool.isPartialInclusion to true, but that is an independent choice you can make.

Note that the code above does not treat labels on Links the same as the way that you are asking for. That’s because the Part.selectionObject for Links is typically the main Shape, so arrowheads would be excluded under your stated policy. You can remove the check for part instanceof go.Link if you like in your app.