// snaps only when the mouse is released without shift modifier
var e = this.diagram.lastInput;
var snap = this.isGuidelineSnapEnabled && !e.shift;
this.showHorizontalMatches(part, this.isGuidelineEnabled, snap);
this.showVerticalMatches(part, this.isGuidelineEnabled, snap);
}
I’d like to add this same feature to control (e.g. disable or toggle) the normal snapping that’s available when dragging and resizing (i.e. when draggingTool.isGridEnabled == true).
Is this possible? Is the dragging tool code available for modification?
You did forget to return the Point returned by the base method.
myDiagram.toolManager.draggingTool.computeMove = function(n, newloc, draggedparts, result) {
var e = this.diagram.lastInput;
var oldsnap = this.isGridSnapEnabled;
if (e.shift) this.isGridSnapEnabled = false;
// call default functionality
var result = go.DraggingTool.prototype.computeMove.call(this, n, newloc, draggedparts, result);
this.isGridSnapEnabled = oldsnap; // restore the original value
return result;
}
Now when DraggingTool.isGridSnapEnabled is true, the behavior is the same as before. But when holding down the Shift key, grid snapping is disabled. That’s true for copying as well as moving.
I’ve used above code to achieve something similar, but without luck so far.
I’d like to turn on grid snapping on alt key, but when user does resizing of a part.
Code simply does not work, but I see that breakpoints are hit and isGridSnapEnabled is set to right value.
I did minor changes to code: computeMove to computeResize etc. Please find it below.
CustomResizeTool.prototype.computeResize = function () {
var e = this.diagram.lastInput;
var oldSnap = this.isGridSnapEnabled;
var result;
if (e.alt)
this.isGridSnapEnabled = e.alt;
result = go.ResizingTool.prototype.computeResize.apply(this, arguments);
this.isGridSnapEnabled = oldSnap;
return result;
};
I’ve made other test and I did a code which sets isGridSnapEnabled before ResizingTool is activated. In this scenario everything works fine.
Steps:
I hit alt key
I do resize
Snap works fine
But when I release alt key while doing resize it does not work correctly too.
Yes, it’s true that it only ResizingTool.computeCellSize checks ResizingTool.isGridSnapEnabled, and that it only calls that method when the tool is activated.
But you have the right idea for doing it continually: overriding ResizingTool.computeResize. What you need to do is pass the desired Size as the cell size in the call to the super method.