From ba890518b5a35d5e6893f9fc72d2eee30ae07e17 Mon Sep 17 00:00:00 2001 From: Pushkar Joshi Date: Fri, 4 May 2012 16:04:04 -0700 Subject: handle delete more correctly than before (selected subpaths are deleted)....this is buggy when the second anchor of a two-anchor subpath is deleted (since the first anchor needs to be converted back into stage world coords) --- js/tools/PenTool.js | 55 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 17 deletions(-) (limited to 'js/tools') diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js index 2e2570e3..fb7f6d6d 100755 --- a/js/tools/PenTool.js +++ b/js/tools/PenTool.js @@ -1402,38 +1402,57 @@ exports.PenTool = Montage.create(ShapeTool, { value: function(event){ //clear the selected subpath...the only new additions to this function w.r.t. ToolBase if (this._selectedSubpath){ + var removeSelectedSubpathCanvas = false; + var removeSelectedSubpath = true; //this is applicable only if the subpath canvas is to be removed if (this._selectedSubpath.getSelectedAnchorIndex()>=0){ this._hoveredAnchorIndex=-1; this._selectedSubpath.removeAnchor(this._selectedSubpath.getSelectedAnchorIndex()); this._selectedSubpath.createSamples(false); //clear the canvas this.application.ninja.stage.clearDrawingCanvas();//stageManagerModule.stageManager.clearDrawingCanvas(); + this.PrepareSelectedSubpathForRendering(); this.DrawSubpathAnchors(this._selectedSubpath); - this.ShowSelectedSubpath(); + var newNumAnchors = this._selectedSubpath.getNumAnchors(); + if (newNumAnchors>1) { + this.ShowSelectedSubpath(); + } else { + if (newNumAnchors===0){ + removeSelectedSubpath = true; + } else{ + removeSelectedSubpath = false; //don't remove the selected subpath if there is still one anchor + } + removeSelectedSubpathCanvas = true; + } + } else { + //if no anchor was selected but the subpath was selected, we will remove the subpath + removeSelectedSubpathCanvas = true; + } + if (removeSelectedSubpathCanvas) { + if (removeSelectedSubpath){ + this._selectedSubpath.clearAllAnchors(); //perhaps unnecessary + this._selectedSubpath = null; + if (this._entryEditMode === this.ENTRY_SELECT_PATH){ + this._entryEditMode = this.ENTRY_SELECT_NONE; + } + } + //clear the canvas + this.application.ninja.stage.clearDrawingCanvas();//stageManagerModule.stageManager.clearDrawingCanvas(); + + //undo/redo...go through ElementController and NJEvent + var els = []; + ElementController.removeElement(this._selectedSubpathCanvas); + els.push(this._selectedSubpathCanvas); + NJevent( "elementsRemoved", els ); + this._selectedSubpathCanvas = null; } - else { - this._selectedSubpath.clearAllAnchors(); //perhaps unnecessary - this._selectedSubpath = null; - if (this._entryEditMode === this.ENTRY_SELECT_PATH){ - this._entryEditMode = this.ENTRY_SELECT_NONE; - } - //clear the canvas - this.application.ninja.stage.clearDrawingCanvas();//stageManagerModule.stageManager.clearDrawingCanvas(); - - //undo/redo...go through ElementController and NJEvent - var els = []; - ElementController.removeElement(this._selectedSubpathCanvas); - els.push(this._selectedSubpathCanvas); - NJevent( "elementsRemoved", els ); - this._selectedSubpathCanvas = null; - } } else { //undo/redo...go through ElementMediator (see ElementMediator.handleDeleting() from where the much of this function is copied) //clear the canvas this.application.ninja.stage.clearDrawingCanvas();//stageManagerModule.stageManager.clearDrawingCanvas(); var els = []; + var len = this.application.ninja.selectedElements.length; for(var i = 0; i