I am trying to add functionality to a go.js diagram such that, you can only create links when the shift key is pressed. I can do that fine. But as a consequence, I don't want the user to be able to move the node when the shift key is pressed.
To achieve part 1, I overrode linkingTool.canStart
. This achieved that goal admerably.
To achieve part 2, I overrode draggingTool.canStart
. This stops the ability to drag nodes but breaks part 1 with an Uncaught TypeError: this.findLinkablePort is not a function
.
tool = myDiagram.toolManager.linkingTool
tool.canStart = function(){
return event.shiftKey && go.LinkingTool.prototype.canStart.call(tool)
}
tool = myDiagram.toolManager.draggingTool
tool.canStart = function(){
return !event.shiftKey && go.DraggingTool.prototype.canStart.call(tool)
}
My assumption is that linkingTool
uses draggingTool
somehow, but I cant find that in the API and I don't know what I can do to fix it. Any ideas as to what is going on?
You can't depend on event
in event.shiftKey
. Instead use this.diagram.lastInput.shift
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.