On selection END event

At the moment there’s an onselectionchange event.

penpot.on('selectionchange', (newSelectionIds) => {
}

However, this fires repeatedly while the user is dragging a selection marquee. This makes it particularly difficult to work with as there’s no sure fire way to filter out all the times you don’t want it to fire.

Is there a way to achieve an onselectionend event for when the user releases their mouse and solidifies their selection?

I see that there’s a finish event, but I couldn’t figure out when this fires (And it doesn’t seem related)

Thanks!
Dale.

Currently I handle it like this:

let selectionIds = penpot.selection.map(node => node.id);

penpot.on('selectionchange', eventIds => {
  if (selectionIds.toString() !== eventIds.toString()) {
    selectionIds = [...eventIds];
    console.log('selectionchange', selectionIds)
  }
})

Thus, the array of IDs is output to the console only after the values of one of the arrays do not match the other.

Thank you!
That’s actually very similar to how I’m handling it (though I debounce the function as well).

Unfortunately, yours will still fire multiple times while dragging a selection over a series of shapes (after each one selects or deselects), and it will slow the performance the larger the selection.

Und mine has the issue of having a delay before being able to take action.