Google Slides Elements Selection Order Issue

a 夏天 提交于 2020-08-08 05:31:39

问题


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
}

回答1:


As stated by @Tanaike, the method getPageElements returns the elements and shapes rendered on the page in no particular order and therefore you will not be able to retrieve them in any particular order.

As @Tanaike mentioned, you can make a feature request asking for getting these elements in the order of your selection.



来源:https://stackoverflow.com/questions/62483449/google-slides-elements-selection-order-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!