在编辑器启动器中复制和粘贴
Remotion 编辑器入门实现了从图层复制和粘贴的功能。
🌐 The Remotion Editor Starter implements copying and pasting from layers.
考虑因素
🌐 Considerations
在阅读浏览器的 Clipboard API 时,仅支持以下 MIME 类型:
🌐 When reading the browser's Clipboard API, only the following MIME types are supported:
text/plaintext/htmlimage/png
这些都不是复制项目的理想 MIME 类型。
🌐 None of these are the ideal MIME types for copying items.
因此,我们正在使用一种由 Figma 和 tldraw 使用的解决方法:将项目序列化,放入一个 <div> 中,然后以 MIME 类型 text/html 复制到剪贴板。这可以防止覆盖 text/plain 插槽。
🌐 We are therefore using a workaround that is used by Figma and tldraw: The items are serialized, put into a <div> and then copied to the clipboard with the MIME type text/html. This prevents overwriting the text/plain slot.
复制粘贴的方法
🌐 Ways of copy-pasting
复制和粘贴可以通过右键点击项目,或使用标准键盘快捷键来实现:
🌐 Copy and pasting works by right-clicking on an item, or using the standard keyboard shortcuts:
- 命令/控制+X 来剪切
- 命令/控制+C 来复制
- Cmd/Ctrl+V 来粘贴
粘贴
🌐 Pasting
在粘贴内容时,编辑器入门版首先会检查剪贴板数据是否具有 MIME 类型 text/html,并将 <div> 的内容反序列化为项目。
🌐 When pasting contents, the Editor Starter first checks if the clipboard data has the MIME type text/html and deserializes the contents of the <div> into items.
项目在被添加到时间轴顶部之前会被复制并分配一个新的唯一ID。
🌐 Items are being copied and assigned a new unique ID before being added to the top of the timeline.
自定义
🌐 Customizing
复制粘贴的逻辑可以在 src/editor/clipboard 中找到。
🌐 The logic for copy-paste can be found under src/editor/clipboard.
另请参阅
🌐 See also