Skip to main content

selection

The selected nodes on this page. Each page stores its own selection separately. The ordering of nodes in the selection is unspecified, you should not be relying on it.

Supported on:

Signature

selection: ReadonlyArray<SceneNode>

Remarks

Like many of our array properties, page.selection returns a new, read-only array every time it is called (the nodes inside are references to existing nodes, not copies). To change the selection, you will need to make a copy of the existing array and/or assign a new array.

Example:

function addNewNodeToSelection(page: PageNode, node: SceneNode) {
// .concat() creates a new array
page.selection = page.selection.concat(node)
}

function selectFirstChildOfNode(page: PageNode, node: SceneNode) {
if (node.children.length > 0) {
page.selection = [node.children[0]]
}
}
  • As the selection is just a node property, the selection is preserved when the user switches between pages.
  • Nodes in the selection are unique. When setting the selection, the API will de-deduplicate nodes in the selection. This API could have been a Set<SceneNode>, but it's generally easier to work with array and to get the first node using just selection[0].
  • Only directly selected nodes are present in this array. A node is directly selected when it is selected and none of its ancestors are selected. That means the array will never contain both a node and one of its descendents.

Possible error cases

Cannot select the document node

Cannot select the document node

The selection of a page can only include nodes in that page