撤销和重做
编辑器入门版实现了一个基本的撤销和重做功能。 它的工作原理是将编辑器的可撤销状态的快照数组保存在内存中。
🌐 The Editor Starter implements a basic Undo and Redo feature.
It works by keeping an array of snapshots of the undoable state of the editor in memory.
撤销栈
🌐 Undo stack
撤销堆栈是存储在内存中的先前状态的数组。 默认情况下,撤销堆栈保存50个状态。
🌐 An undo stack is an array of previous states that is being kept in memory.
By default, the undo stack holds 50 states.
每当更新状态时,你应该适当地设置 commitToUndoStack 属性,以指示该状态更新是否应提交到撤销栈。
🌐 Whenever updating a state, you should set the commitToUndoStack property appropriately to indicate whether the state update should be committed to the undo stack.
你可能不想添加到撤销栈的操作是像以下这样的高频状态更新:
🌐 Actions that you may not want to add to the undo stack are high-frequency state update like:
- 在画布中拖动一个项目
- 在时间轴中拖动一个项目
- 在时间轴中修剪项目
- 在检查器中使用滑块更改值
在这些情况下,只有在释放鼠标光标时才适合提交到撤销栈。
🌐 In these cases, it is appropriate to only commit to the undo stack once the mouse cursor is released.
防止不必要地向撤销堆栈添加内容
🌐 Preventing unnecessary additions to the undo stack
撤销栈只有在状态对象引用实际发生变化时才会添加新条目。
如果状态更新导致 oldState === newState 评估为 true,则不会向撤销栈添加条目。
🌐 The undo stack only adds a new entry when the state object reference actually changes.
If a state update results in oldState === newState evaluating to true, no entry is added to the undo stack.
有关更多信息,请参阅 在没有变化时防止状态更新。
🌐 See Preventing state updates when nothing has changed for more information.
撤销和重做操作
🌐 Undo and Redo interactions
你可以撤销和重做操作:
🌐 You can undo and redo actions:
- 通过使用按钮
- 内置快捷键: Ctrl + Z 用于撤销, Ctrl + Y 用于重做。
此行为由以下标志控制:
🌐 This behavior is controlled by the following flags:
另请参阅
🌐 See also