Setting the selection, preventing Edit Context Error and method to check if a node is in a container

selection

#1

I’m working on selecting a few elements on an artboard and I’m getting an error sometimes.

var selectedItems = [item1, item2];
selection.items = selectItems;

Error: Cannot select node not in the current edit context: [object Object]
at plugins/SelectionWrapper.js:1:918

It seems it may happen if one scene node is owned by another scene node and I’m setting the selection to both.

For example, when I select a text node inside a container and also select the container. Selecting the text node opens a new context on the artboard.

So is there a method to check if a node is contained in another node?

for (var i=0;i<selectedItems.length;i++) {
    if (selectedItems[i].isContainer && selectedItems[i].contains(newItem)!=true) {
        selectedItems.push(newItem); 
    }
}

If I assign the selection to a lot of nodes I want to prevent this error.


#2

Further discussion question

If the artboard is selected and I want to select a text scene node on that artboard and the scene node is inside a group the selection.items = textSceneNode will throw an error.

Do you think when this scenario is encountered should the node be selected or should it throw an error?