From 346e5b4ac8632f62aa313e52f8a6bebc9ae263ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=97=E8=A7=92=E5=B0=8F=E6=9E=97?= <1013335014@qq.com> Date: Mon, 18 Dec 2023 10:35:19 +0800 Subject: [PATCH] =?UTF-8?q?Feat=EF=BC=9Arender=E5=AE=9E=E4=BE=8B=E7=9A=84p?= =?UTF-8?q?aste=E6=96=B9=E6=B3=95=E6=94=B9=E4=B8=BA=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E7=B2=98=E8=B4=B4=E5=89=AA=E8=B4=B4=E6=9D=BF=E7=9A=84=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/core/render/Render.js | 30 +++++++++++------------ 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/simple-mind-map/src/core/render/Render.js b/simple-mind-map/src/core/render/Render.js index 54aa33bb..9c995e37 100644 --- a/simple-mind-map/src/core/render/Render.js +++ b/simple-mind-map/src/core/render/Render.js @@ -320,16 +320,18 @@ class Render { this.mindMap.keyCommand.addShortcut('Control+Down', () => { this.mindMap.execCommand('DOWN_NODE') }) - // 复制节点、剪切节点、粘贴节点的快捷键需开发者自行注册实现,可参考demo + // 复制节点、 this.mindMap.keyCommand.addShortcut('Control+c', () => { this.copy() }) - this.mindMap.keyCommand.addShortcut('Control+v', () => { - this.onPaste() - }) + // 剪切节点 this.mindMap.keyCommand.addShortcut('Control+x', () => { this.cut() }) + // 粘贴节点 + this.mindMap.keyCommand.addShortcut('Control+v', () => { + this.paste() + }) // 根节点居中显示 this.mindMap.keyCommand.addShortcut('Control+Enter', () => { this.setRootNodeCenter() @@ -873,6 +875,7 @@ class Render { // 复制节点 copy() { this.beingCopyData = this.copyNode() + if (!this.beingCopyData) return setDataToClipboard({ simpleMindMap: true, data: this.beingCopyData @@ -889,16 +892,9 @@ class Render { }) }) } - - // 粘贴节点 - paste() { - if (this.beingCopyData) { - this.mindMap.execCommand('PASTE_NODE', this.beingCopyData) - } - } - - // 粘贴事件 - async onPaste() { + + // 粘贴 + async paste() { const { errorHandler, handleIsSplitByWrapOnPasteCreateNewNode } = this.mindMap.opt // 读取剪贴板的文字和图片 @@ -1020,7 +1016,9 @@ class Render { } } else { // 粘贴节点数据 - this.paste() + if (this.beingCopyData) { + this.mindMap.execCommand('PASTE_NODE', this.beingCopyData) + } } } @@ -1212,7 +1210,7 @@ class Render { // 复制节点 copyNode() { if (this.activeNodeList.length <= 0) { - return + return null } const nodeList = getTopAncestorsFomNodeList(this.activeNodeList) return nodeList.map(node => {