if I put a html input textbox next to a gojs diagram… when I try to select the text in the html input by clicking, dragging and then releasing the mouse over the diagram the text does not get selected.
it helps if I don’t call the go.ToolManager.prototype.doMouseUp function… then the text can be selected just fine in my scenario.
but I guess doMouseUp function is pretty important to goJS… :D
so… any ideas?
it’s easy to test… just inject a textbox into any sample page and you’ll see the issue.
I’m sorry, but I am unable to reproduce the behavior that you are seeing. I tried it at Org Chart Editor.
I believe that for most s when the user uses a mouse to select text, the mouse is “captured”. That means the Diagram will not receive any mouse events while dragging the mouse when initiated within the TextArea.
Oh, I think I see what you mean: You start the drag on the textblock, hold your mouse and release the mouse while over the Diagram. In that case, for me, all browsers act the same.
What if you just remembered which mouse actions began on the Diagram, and if they did not begin on the Diagram, don’t let GoJS’ default actions (which involve calling Diagram.focus() on doMouseUp) to occur.
var mouseOnDiagram = false;
myDiagram.toolManager.doMouseDown = function () {
go.ToolManager.prototype.doMouseDown.call(this);
mouseOnDiagram = true;
};
myDiagram.toolManager.doMouseUp = function () {
if (mouseOnDiagram) {
go.ToolManager.prototype.doMouseUp.call(this);
}
mouseOnDiagram = false;
};
The reason that your code didn’t work is most likely because of the call to focus that the regular doMouseUp call does.
So, Simon, you are saying that the alpha version of Chrome now behaves the same way that Firefox and InternetExplorer do, even though the current version of Chrome behaves differently.
But I still do not understand what it is that the original poster is asking about.
@walter, catface is saying that any mouseUp on the Diagram, even when the mouseDown began elsewhere, is causing the Diagram to focus, which is causing his TextArea to lose focus. This is intentional behavior on part of the Diagram, because we often want events that go:
mouseDown on element A
mouseUp on Diagram B
to focus Diagram B. (For instance if Element A was a Palette, or an HTML element that was supposed to be “dropped” onto the Diagram, or even something dragged in from outside the Diagram window).
catface’s element A is a text area/input, and he does not want it to lose focus when he selects the text and (perhaps accidentally) mouses up over the diagram at the end of the text selection. I think this is understandable to want, but you have to explicitly turn off the focus-on-mouseup that GoJS is doing to achieve it.
But when I start dragging within a TextArea and release (mouse-up) in a Diagram, the Diagram does not get focus. That is the case in both Firefox and IE11.
but for some reason that looks like a hack to me… would it be possible to only do focus on mouse down?.. or at mouse up, but only if the corresponding mouse down was also on the diagram?
Hello @Dominic.Lerbs, not particularly. You do have the option to override the focus method:
myDiagram.focus = function() {
// Maybe decide to do something differently
if (/* TODO some criteria */) {
// Do different behavior, and do not focus the Diagram
// ... TODO
} else {
// do the default behavior
go.Diagram.prototype.focus.call(this);
}
}
But you would have to come up with some other criteria to specify to stop the focusing.