Made some optimizations related to selections
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1730 eee81c28-f429-11dd-99c0-75d572ba1ddd
This commit is contained in:
@@ -367,8 +367,6 @@ svgEditor.addExtension("shapes", function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
canv.clearSelection();
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
keep: true,
|
keep: true,
|
||||||
element: cur_shape,
|
element: cur_shape,
|
||||||
|
|||||||
@@ -4067,6 +4067,7 @@ var clearSelection = this.clearSelection = function(noCall) {
|
|||||||
|
|
||||||
// TODO: do we need to worry about selectedBBoxes here?
|
// TODO: do we need to worry about selectedBBoxes here?
|
||||||
|
|
||||||
|
|
||||||
// Function: addToSelection
|
// Function: addToSelection
|
||||||
// Adds a list of elements to the selection. The 'selected' handler is then called.
|
// Adds a list of elements to the selection. The 'selected' handler is then called.
|
||||||
//
|
//
|
||||||
@@ -4132,6 +4133,16 @@ var addToSelection = this.addToSelection = function(elemsToAdd, showGrips) {
|
|||||||
while(selectedElements[0] == null) selectedElements.shift(0);
|
while(selectedElements[0] == null) selectedElements.shift(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Function: selectOnly()
|
||||||
|
// Selects only the given elements, shortcut for clearSelection(); addToSelection()
|
||||||
|
//
|
||||||
|
// Parameters:
|
||||||
|
// elems - an array of DOM elements to be selected
|
||||||
|
var selectOnly = this.selectOnly = function(elems, showGrips) {
|
||||||
|
clearSelection(true);
|
||||||
|
addToSelection(elems, showGrips);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: could use slice here to make this faster?
|
// TODO: could use slice here to make this faster?
|
||||||
// TODO: should the 'selected' handler
|
// TODO: should the 'selected' handler
|
||||||
|
|
||||||
@@ -4170,13 +4181,10 @@ var removeFromSelection = this.removeFromSelection = function(elemsToRemove) {
|
|||||||
|
|
||||||
// Function: selectAllInCurrentLayer
|
// Function: selectAllInCurrentLayer
|
||||||
// Clears the selection, then adds all elements in the current layer to the selection.
|
// Clears the selection, then adds all elements in the current layer to the selection.
|
||||||
// This function then fires the selected event.
|
|
||||||
this.selectAllInCurrentLayer = function() {
|
this.selectAllInCurrentLayer = function() {
|
||||||
if (current_layer) {
|
if (current_layer) {
|
||||||
clearSelection();
|
selectOnly($(current_layer).children());
|
||||||
addToSelection($(current_layer).children());
|
|
||||||
current_mode = "select";
|
current_mode = "select";
|
||||||
call("selected", selectedElements);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -5292,9 +5300,8 @@ var getMouseTarget = this.getMouseTarget = function(evt) {
|
|||||||
t.id != "svgcanvas" && t.id != "svgroot")
|
t.id != "svgcanvas" && t.id != "svgroot")
|
||||||
{
|
{
|
||||||
// switch into "select" mode if we've clicked on an element
|
// switch into "select" mode if we've clicked on an element
|
||||||
clearSelection(true);
|
|
||||||
addToSelection([t], true);
|
|
||||||
canvas.setMode("select");
|
canvas.setMode("select");
|
||||||
|
selectOnly([t], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (element != null) {
|
} else if (element != null) {
|
||||||
@@ -5326,8 +5333,7 @@ var getMouseTarget = this.getMouseTarget = function(evt) {
|
|||||||
// keep us in the tool we were in unless it was a text or image element
|
// keep us in the tool we were in unless it was a text or image element
|
||||||
addToSelection([element], true);
|
addToSelection([element], true);
|
||||||
} else {
|
} else {
|
||||||
clearSelection(true);
|
selectOnly([element], true);
|
||||||
addToSelection([element], true);
|
|
||||||
}
|
}
|
||||||
// we create the insert command that is stored on the stack
|
// we create the insert command that is stored on the stack
|
||||||
// undo means to call cmd.unapply(), redo means to call cmd.apply()
|
// undo means to call cmd.unapply(), redo means to call cmd.apply()
|
||||||
@@ -8156,8 +8162,7 @@ var convertToGroup = this.convertToGroup = function(elem) {
|
|||||||
if(!this.id) this.id = getNextId();
|
if(!this.id) this.id = getNextId();
|
||||||
});
|
});
|
||||||
|
|
||||||
clearSelection();
|
selectOnly([g]);
|
||||||
addToSelection([g]);
|
|
||||||
|
|
||||||
addCommandToHistory(batchCmd);
|
addCommandToHistory(batchCmd);
|
||||||
|
|
||||||
@@ -10400,8 +10405,7 @@ this.pasteElements = function(type) {
|
|||||||
batchCmd.addSubCommand(new InsertElementCommand(copy));
|
batchCmd.addSubCommand(new InsertElementCommand(copy));
|
||||||
}
|
}
|
||||||
|
|
||||||
clearSelection(true);
|
selectOnly(pasted);
|
||||||
addToSelection(pasted);
|
|
||||||
|
|
||||||
if(type !== 'in_place') {
|
if(type !== 'in_place') {
|
||||||
var bbox = getStrokedBBox(pasted);
|
var bbox = getStrokedBBox(pasted);
|
||||||
@@ -10450,8 +10454,7 @@ this.groupSelectedElements = function() {
|
|||||||
if (!batchCmd.isEmpty()) addCommandToHistory(batchCmd);
|
if (!batchCmd.isEmpty()) addCommandToHistory(batchCmd);
|
||||||
|
|
||||||
// update selection
|
// update selection
|
||||||
clearSelection();
|
selectOnly([g], true);
|
||||||
addToSelection([g], true);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function: ungroupSelectedElement
|
// Function: ungroupSelectedElement
|
||||||
@@ -10813,7 +10816,7 @@ this.cloneSelectedElements = function() {
|
|||||||
}
|
}
|
||||||
// use slice to quickly get the subset of elements we need
|
// use slice to quickly get the subset of elements we need
|
||||||
var copiedElements = selectedElements.slice(0,i);
|
var copiedElements = selectedElements.slice(0,i);
|
||||||
this.clearSelection();
|
this.clearSelection(true);
|
||||||
// note that we loop in the reverse way because of the way elements are added
|
// note that we loop in the reverse way because of the way elements are added
|
||||||
// to the selectedElements array (top-first)
|
// to the selectedElements array (top-first)
|
||||||
var i = copiedElements.length;
|
var i = copiedElements.length;
|
||||||
@@ -10828,7 +10831,6 @@ this.cloneSelectedElements = function() {
|
|||||||
addToSelection(copiedElements.reverse()); // Need to reverse for correct selection-adding
|
addToSelection(copiedElements.reverse()); // Need to reverse for correct selection-adding
|
||||||
this.moveSelectedElements(20,20,false);
|
this.moveSelectedElements(20,20,false);
|
||||||
addCommandToHistory(batchCmd);
|
addCommandToHistory(batchCmd);
|
||||||
call("selected", selectedElements);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -11027,8 +11029,7 @@ this.cycleElement = function(next) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
clearSelection();
|
selectOnly([elem], true);
|
||||||
addToSelection([elem], true);
|
|
||||||
call("selected", selectedElements);
|
call("selected", selectedElements);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user