Currently, when a node is selected in the graph, clicking the empty space in the canvas clears the selection.
I see that Diagram has a property called maxSelectionCount for changing the maximum number of nodes that can be selected. I was thinking if there is some way to manually implement functionality that would be similar to:
diagram.minSelectionCount = 1
to make sure clicking on the empty canvas does not deselect the only selected node.
Override ClickSelectingTool.standardMouseSelect to do what you want.
Here is its definition in the base Tool class, Tool | GoJS API :
public standardMouseSelect(): void {
const diagram = this.diagram;
if (!diagram.allowSelect) return;
const e = diagram.lastInput;
const curobj = diagram.findPartAt(e.documentPoint, false); // to select containing Group if Part.canSelect() is false
if (curobj !== null) {
if (e.meta || e.control) { // toggle the part's selection
diagram.raiseDiagramEvent('ChangingSelection', diagram.selection);
let part = curobj;
while (part !== null && !part.canSelect()) part = part.containingGroup;
if (part !== null) part.isSelected = !part.isSelected;
diagram.raiseDiagramEvent('ChangedSelection', diagram.selection);
} else if (e.shift) { // add the part to the selection
if (!curobj.isSelected) {
diagram.raiseDiagramEvent('ChangingSelection', diagram.selection);
let part = curobj;
while (part !== null && !part.canSelect()) part = part.containingGroup;
if (part !== null) part.isSelected = true;
diagram.raiseDiagramEvent('ChangedSelection', diagram.selection);
}
} else {
if (!curobj.isSelected) {
let part = curobj;
while (part !== null && !part.canSelect()) part = part.containingGroup;
if (part !== null) diagram.select(part); // also raises ChangingSelection/Finished
}
}
} else if (e.left && !(e.meta || e.control) && !e.shift) {
// left click on background with no modifier: clear selection
diagram.clearSelection(); // also raises ChangingSelection/Finished
}
}
Note the call to Diagram.clearSelection, which you want to avoid here.