From 40a4d9dbc12e802e2d0a7c3acd69bc7e394d4529 Mon Sep 17 00:00:00 2001 From: Pushkar Joshi Date: Fri, 27 Apr 2012 10:03:58 -0700 Subject: Fix for 1525 Pen: "Uncaught RangeError: Maximum call stack size exceeded". (check if the second mouse click actually selects the existing first anchor point) --- js/tools/PenTool.js | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) (limited to 'js/tools/PenTool.js') diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js index 8ecc9f79..8cc32536 100755 --- a/js/tools/PenTool.js +++ b/js/tools/PenTool.js @@ -273,14 +273,36 @@ exports.PenTool = Montage.create(ShapeTool, { var swMousePos = hitRec.calculateStageWorldPoint(); swMousePos[0]+= snapManager.getStageWidth()*0.5; swMousePos[1]+= snapManager.getStageHeight()*0.5; - this._selectedSubpath.addAnchor(new AnchorPoint()); - var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); - newAnchor.setPos(swMousePos[0], swMousePos[1], swMousePos[2]); - newAnchor.setPrevPos(swMousePos[0], swMousePos[1], swMousePos[2]); - newAnchor.setNextPos(swMousePos[0], swMousePos[1], swMousePos[2]); - //set the mode so that dragging will update the next and previous locations - this._editMode = this.EDIT_PREV_NEXT; - } + //check if the mouse click location is close to the existing anchor + var indexAndCode = this._selectedSubpath.pickAnchor(swMousePos[0], swMousePos[1], swMousePos[2], this._PICK_POINT_RADIUS); + if (indexAndCode[0]>=0){ + //the anchor point was hit, so we do not add another anchor + switch(indexAndCode[1]){ + case this._selectedSubpath.SEL_ANCHOR: + this._editMode = this.EDIT_ANCHOR; + break; + case this._selectedSubpath.SEL_PREV: + this._editMode = this.EDIT_PREV; + break; + case this._selectedSubpath.SEL_NEXT: + this._editMode = this.EDIT_NEXT; + break; + default: + this._editMode = this.EDIT_ANCHOR; + console.log("WARNING picked anchor point with incorrect mode"); + break; + } + + } else { + this._selectedSubpath.addAnchor(new AnchorPoint()); + var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); + newAnchor.setPos(swMousePos[0], swMousePos[1], swMousePos[2]); + newAnchor.setPrevPos(swMousePos[0], swMousePos[1], swMousePos[2]); + newAnchor.setNextPos(swMousePos[0], swMousePos[1], swMousePos[2]); + //set the mode so that dragging will update the next and previous locations + this._editMode = this.EDIT_PREV_NEXT; + } + } //if we have not yet created a canvas for this path //the selected subpath has a canvas, so test within that canvas' space else -- cgit v1.2.3