powerpointoffice-jsoffice-addinspowerpoint-addinspowerpoint-web-addins

PowerPoint: How can we create an Undo entry for the actions performed on shapes?


Unexpected behavior of UNDO: When we perform certain actions in PowerPoint using OfficeJS it doesn't create an undo stack. when CTRL + Z is pressed PowerPoint ignores changes made using API.

Example I'm working on an add-in that performs certain design decisions over slide elements, e.g., changing color of a shape group, then maybe resizing it etc. In case add-in performed many actions at once and CTRL + Z is pressed it'll vanish all the changes at once.

The Expected Behavior! In older PowerPoint Object Model there was Application.StartNewUndoEntry method that could be used to batch certain actions in one UNDO stack. I couldn't find anything similar in newer API.

Recreate The Issue Here's an example code:

PowerPoint.run(async context => {
    const slides = context.presentation.slides
    const slide = slides.getItemAt(0);
    await context.sync();
    slide.delete()
    await context.sync();
})

I used above code in script lab that deletes the first slide, if we create 5 slides and run the code twice it'll leave us with only 3 slides. Now pressing UNDO or CTRL + Z should return those slides! that'd be expected behavior but actually those slides are gone permanently!

This is one case...

Another would be: changing the color of the certain shapes, then maybe changing their sizes/positions to make a visualization, then we'll need to create an UNDO entry to undo this group of actions in single undo call. In previous versions it was possible with Application.StartNewUndoEntry, How can we achieve same with newer API?


Solution

  • The Office JavaScript API (OfficeJS) doesn't provide anything for that. You can find a lot of existing issues filed and confirmed related to the Undo operations at https://github.com/OfficeDev/office-js/issues?q=is%3Aissue+is%3Aopen+undo .

    Note, you can post or vote for an existing feature request on Tech Community where they are considered when the Office dev team goes through the planning process.