diff --git a/HISTORY.md b/HISTORY.md index 2d72dfd8..c7517237 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -27,6 +27,7 @@ http://visjs.org - Deprecated event `finishedRedraw` as it's redundant. - Renamed option `animate` to `animation`, and changed it to be either a boolean or an object `{duration: number, easingFunction: string}`. +- Fixed #831: items losing selection when their type changed. ### Graph2d diff --git a/lib/timeline/component/ItemSet.js b/lib/timeline/component/ItemSet.js index 2395cb9a..0d8a96a4 100644 --- a/lib/timeline/component/ItemSet.js +++ b/lib/timeline/component/ItemSet.js @@ -818,11 +818,13 @@ ItemSet.prototype._onUpdate = function(ids) { var type = me._getType(itemData); var constructor = ItemSet.types[type]; + var selected; if (item) { // update item if (!constructor || !(item instanceof constructor)) { // item type has changed, delete the item and recreate it + selected = item.selected; // preserve selection of this item me._removeItem(item); item = null; } @@ -837,6 +839,10 @@ ItemSet.prototype._onUpdate = function(ids) { item = new constructor(itemData, me.conversion, me.options); item.id = id; // TODO: not so nice setting id afterwards me._addItem(item); + if (selected) { + this.selection.push(id); + item.select(); + } } else if (type == 'rangeoverflow') { // TODO: deprecated since version 2.1.0 (or 3.0.0?). cleanup some day @@ -847,7 +853,7 @@ ItemSet.prototype._onUpdate = function(ids) { throw new TypeError('Unknown item type "' + type + '"'); } } - }); + }.bind(this)); this._order(); this.stackDirty = true; // force re-stacking of all items next redraw