PowerPoint: 如何为在形状上执行的操作创建撤销项?

huangapple go评论86阅读模式
英文:

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

问题

UNDO的意外行为:
当我们使用OfficeJS在PowerPoint中执行某些操作时,它不会创建撤销堆栈。当按下CTRL + Z时,PowerPoint会忽略使用API进行的更改。

示例
我正在开发一个插件,用于对幻灯片元素进行某些设计决策,例如更改形状组的颜色,然后可能调整其大小等。如果插件一次执行了许多操作,然后按下CTRL + Z,它将一次性取消所有更改。

期望的行为!
在旧版PowerPoint对象模型中,有一个Application.StartNewUndoEntry方法,可以用来批处理一个UNDO堆栈中的某些操作。在较新的API中,我找不到类似的东西。

重现问题
这是一个示例代码:

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

我在Script Lab中使用上面的代码删除了第一张幻灯片,如果我们创建了5张幻灯片并两次运行该代码,它将只留下3张幻灯片。现在按下UNDO或CTRL + Z应该会恢复这些幻灯片!这是期望的行为,但实际上这些幻灯片永久消失了!

这只是一个情况...

另一个情况可能是:更改某些形状的颜色,然后可能更改它们的大小/位置以创建可视化效果,然后我们需要创建一个UNDO条目,以在单个UNDO调用中撤消此组操作。在以前的版本中,可以使用Application.StartNewUndoEntry来实现相同的效果,如何在较新的API中实现相同的效果?

英文:

Unexpected behavior of UNDO:
When we perform certain actions in PowerPoint using OfficeJS it doesn't create an undo stack.
when <kbd>CTRL + Z</kbd> 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 <kbd>CTRL + Z</kbd> 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:

<!-- language: javascript -->

PowerPoint.run(async context =&gt; {
    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 <kbd>CTRL + Z</kbd> 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?

答案1

得分: 1

办公室 JavaScript API(OfficeJS)没有提供相关功能。您可以在 https://github.com/OfficeDev/office-js/issues?q=is%3Aissue+is%3Aopen+undo 上找到许多与撤销操作相关的现有问题已被记录并确认。

请注意,您可以在 Tech Community 上发布或投票支持现有的功能请求,这些请求将在 Office 开发团队进行规划过程时考虑。

英文:

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.

huangapple
  • 本文由 发表于 2023年6月19日 00:57:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/76501653.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定