I’m trying to handle clicks on a shape in my diagram. In this case, it’s the yellow one that contains “25” as its text. That rounded rectangle shape is part of the nearby link. When nothing is currently selected in my diagram, my “click” handler for that shape is called as I expect. However, when the adjacent node (to the left of my yellow rectangle, with the “this is some really very long text” text) is selected, a click on the “25” rectangle seems to pass right through the rectangle and the “this is some really very” text goes into edit mode. In that case my click handler is never called. (Also, strangely, when I click directly on the “25” text, the click handler of that TextBlock seems to be called every time, regardless of the current selection.)
I’ve intentionally tried putting the links in a higher layer than the nodes to try to solve this, but it doesn’t seem to affect anything.
Why might this be happening? I tried to duplicate this in a simple fiddle, but it doesn’t seem to happen in my simple case, so I was hoping there might be an obvious reason this happens. My goal is for the yellow rectangle’s click handler to get called when it’s clicked, regardless of the current node selection.
Yes, there is a selection adornment on the node, and it’s around the rectangle but not the textblock. It’s also placed on a lower level. Here’s the definition of the selection adornment.
I think I have a simple fiddle now that is doing the same thing that I see in my main app, so maybe this will help.
When nothing is selected, a click on the left side of the red rounded rectangle (pointed to by the blue arrow) will result in the click handler for the rectangle being fired. When instead the node is selected (the node that’s highlighted in my screenshot), clicking in the same place results in the text editor popping up, and the click handler never gets called. My goal is for the rectangle to handle its own click here, regardless of the selection state.
Ah, thanks for finding this subtle bug in TextEditingTool.canStart. You can use this override in a Diagram initialization, until the next release:
$(go.Diagram, . . .,
{ . . .,
"textEditingTool.canStart": function() {
if (!this.isEnabled) return false;
var diagram = this.diagram;
if (diagram === null || diagram.isReadOnly) return false;
// only works with the left button
if (!diagram.lastInput.left) return false;
// the mouse down point needs to be near the mouse up point
if (this.isBeyondDragSize()) return false;
var p = diagram.lastInput.documentPoint;
var tb = diagram.findObjectAt(p);
if (tb === null || !(tb instanceof go.TextBlock)) return false;
if (!tb.editable || !tb.part.canEdit()) return false;
var part = tb.part;
if (part === null) return false;
if (this.starting === TextEditingTool.SingleClickSelected && !part.isSelected) return false;
if (this.starting === TextEditingTool.DoubleClick && diagram.lastInput.clickCount < 2) return false;
return true;
}
})
The next release will probably be next week; you have a work-around and there aren’t any other bugs that need to be fixed, so I assume it can wait.