I was trying to get the selected shapes from the user's current selection in Google slides with Apps Script. The shapes return are not always match the user's selection order.
Example: Let's say we have 4 shapes on the slide, #1, #2, #3, #4. If I select #4, #2, #3, #1 on the slide one by one, the return result should match [shape#4, shape#2, shpae#3, shape#1]. However, I found sometimes the return result is a mess, not reflect the actual order I select. Not sure if this is a bug or something.
Here is my code to get the selected shapes to put them in a list.
function getSelectedShapes(){
let shapes = []
let selections = SlidesApp.getActivePresentation().getSelection()
let pageElementRange = selections.getPageElementRange()
if (pageElementRange){
let elements = pageElementRange.getPageElements()
shapes = elements.map(element=>element.asShape())
}
return shapes
}