Feat:render实例的paste方法改为支持粘贴剪贴板的数据

This commit is contained in:
街角小林 2023-12-18 10:35:19 +08:00
parent 6f7bb40c49
commit 346e5b4ac8

View File

@ -320,16 +320,18 @@ class Render {
this.mindMap.keyCommand.addShortcut('Control+Down', () => { this.mindMap.keyCommand.addShortcut('Control+Down', () => {
this.mindMap.execCommand('DOWN_NODE') this.mindMap.execCommand('DOWN_NODE')
}) })
// 复制节点、剪切节点、粘贴节点的快捷键需开发者自行注册实现可参考demo // 复制节点、
this.mindMap.keyCommand.addShortcut('Control+c', () => { this.mindMap.keyCommand.addShortcut('Control+c', () => {
this.copy() this.copy()
}) })
this.mindMap.keyCommand.addShortcut('Control+v', () => { // 剪切节点
this.onPaste()
})
this.mindMap.keyCommand.addShortcut('Control+x', () => { this.mindMap.keyCommand.addShortcut('Control+x', () => {
this.cut() this.cut()
}) })
// 粘贴节点
this.mindMap.keyCommand.addShortcut('Control+v', () => {
this.paste()
})
// 根节点居中显示 // 根节点居中显示
this.mindMap.keyCommand.addShortcut('Control+Enter', () => { this.mindMap.keyCommand.addShortcut('Control+Enter', () => {
this.setRootNodeCenter() this.setRootNodeCenter()
@ -873,6 +875,7 @@ class Render {
// 复制节点 // 复制节点
copy() { copy() {
this.beingCopyData = this.copyNode() this.beingCopyData = this.copyNode()
if (!this.beingCopyData) return
setDataToClipboard({ setDataToClipboard({
simpleMindMap: true, simpleMindMap: true,
data: this.beingCopyData data: this.beingCopyData
@ -890,15 +893,8 @@ class Render {
}) })
} }
// 粘贴节点 // 粘贴
paste() { async paste() {
if (this.beingCopyData) {
this.mindMap.execCommand('PASTE_NODE', this.beingCopyData)
}
}
// 粘贴事件
async onPaste() {
const { errorHandler, handleIsSplitByWrapOnPasteCreateNewNode } = const { errorHandler, handleIsSplitByWrapOnPasteCreateNewNode } =
this.mindMap.opt this.mindMap.opt
// 读取剪贴板的文字和图片 // 读取剪贴板的文字和图片
@ -1020,7 +1016,9 @@ class Render {
} }
} else { } else {
// 粘贴节点数据 // 粘贴节点数据
this.paste() if (this.beingCopyData) {
this.mindMap.execCommand('PASTE_NODE', this.beingCopyData)
}
} }
} }
@ -1212,7 +1210,7 @@ class Render {
// 复制节点 // 复制节点
copyNode() { copyNode() {
if (this.activeNodeList.length <= 0) { if (this.activeNodeList.length <= 0) {
return return null
} }
const nodeList = getTopAncestorsFomNodeList(this.activeNodeList) const nodeList = getTopAncestorsFomNodeList(this.activeNodeList)
return nodeList.map(node => { return nodeList.map(node => {