我正在构建一个使用 JointsJS + Rappid 操作图表的管理工具。我正在尝试将粘贴元素从一张纸 A 复制到另一张纸 B(位于不同的浏览器选项卡上),但我面临以下问题:
- 我可以将一组元素从 A 复制粘贴到 B(这很好)
- 我什至可以粘贴几次(还是不错的)
- 但是如果我从 A 复制另一组元素,并尝试将其粘贴到 B 中,则会粘贴前一组,而不是新的一组
- 我仍然可以将元素从 A 粘贴到 A 中,将 B 粘贴到 B 中,但不能再从一个粘贴到另一个。
在Kitchen Sink Rappid 演示中,这种行为似乎是相同的:如果我在演示中打开 2 个选项卡,我将面临完全相同的问题。您可以通过使用演示应用程序打开 2 个选项卡轻松复制它。
这是我的一段代码(直接取自 Rappid 演示):
this.clipboard = new joint.ui.Clipboard();
this.selection = new joint.ui.Selection({
paper: this.paper,
handles: App.config.selection.handles,
collection: new Backbone.Collection
});
this.keyboard = new joint.ui.Keyboard();
this.keyboard.on({
'ctrl+c': function () {
// Copy all selected elements and their associated links.
this.clipboard.copyElements(this.selection.collection, this.graph);
},
'ctrl+v': function () {
var pastedCells = this.clipboard.pasteCells(this.graph, {
translate: {dx: 20, dy: 20},
useLocalStorage: true
});
var elements = _.filter(pastedCells, function (cell) {
return cell.isElement();
});
// Make sure pasted elements get selected immediately. This makes the UX better as
// the user can immediately manipulate the pasted elements.
this.selection.collection.reset(elements);
},
}
在 Rappid 文档中,指出:
“此外,剪贴板还能够从一张纸复制单元格并将它们粘贴到另一张纸上。但是,目标纸的确定留给应用层。”
我没有完全理解第二句话(“但是……”结束)。
我监控了本地存储,发现两篇论文可能使用了相同的存储条目,这让我觉得图间粘贴是有管理的。
在这个阶段,我正在努力寻找是否:
- 我的代码应该完全执行图间复制粘贴,
- 我做错了,
- Rappid 有一个 bug(考虑到这个行为在官方演示中是一样的)。
谢谢你的帮助。