mirror of
https://github.com/konvajs/konva.git
synced 2025-12-17 18:01:15 +08:00
fix remove name bug
This commit is contained in:
22
src/Node.js
22
src/Node.js
@@ -1421,10 +1421,26 @@
|
||||
return this;
|
||||
},
|
||||
setName: function(name) {
|
||||
var oldName = this.getName();
|
||||
debugger;
|
||||
var oldNames = (this.getName() || '').split(/\s/g);
|
||||
var newNames = (name || '').split(/\s/g);
|
||||
var subname, i;
|
||||
// remove all subnames
|
||||
for(i = 0; i < oldNames.length; i++) {
|
||||
subname = oldNames[i];
|
||||
if ((newNames.indexOf(subname)) === -1 && subname) {
|
||||
Konva._removeName(subname, this._id);
|
||||
}
|
||||
}
|
||||
|
||||
// add new names
|
||||
for(i = 0; i < newNames.length; i++) {
|
||||
subname = newNames[i];
|
||||
if ((oldNames.indexOf(subname) === -1) && subname) {
|
||||
Konva._addName(this, subname);
|
||||
}
|
||||
}
|
||||
|
||||
Konva._removeName(oldName, this._id);
|
||||
Konva._addName(this, name);
|
||||
this._setAttr(NAME, name);
|
||||
return this;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user