From c428f166a60fb833f106bdee9a502cc0a4fd5bad Mon Sep 17 00:00:00 2001 From: esky-wh Date: Thu, 14 Sep 2023 14:11:13 +0800 Subject: [PATCH] =?UTF-8?q?Feat:=201.=E6=B7=BB=E5=8A=A0=E5=BC=80=E5=90=AF?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E8=8A=82=E7=82=B9=E5=90=8E=E6=BF=80=E6=B4=BB?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E9=85=8D=E7=BD=AE2.=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=88=A0=E9=99=A4=E8=8A=82=E7=82=B9=E5=90=8E?= =?UTF-8?q?=E6=BF=80=E6=B4=BB=E7=9B=B8=E9=82=BB=E8=8A=82=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/constants/defaultOptions.js | 4 ++- simple-mind-map/src/core/render/Render.js | 30 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/simple-mind-map/src/constants/defaultOptions.js b/simple-mind-map/src/constants/defaultOptions.js index 1f1b5709..14db4e59 100644 --- a/simple-mind-map/src/constants/defaultOptions.js +++ b/simple-mind-map/src/constants/defaultOptions.js @@ -182,5 +182,7 @@ export const defaultOpt = { // 节点鼠标hover和激活时显示的矩形边框距节点内容的距离 hoverRectPadding: 2, // 双击节点进入节点文本编辑时是否默认选中文本,默认只在创建新节点时会选中 - selectTextOnEnterEditText: false + selectTextOnEnterEditText: false, + // 删除节点后激活相邻节点 + deleteNodeActive: true, } diff --git a/simple-mind-map/src/core/render/Render.js b/simple-mind-map/src/core/render/Render.js index 230713cb..5886e490 100644 --- a/simple-mind-map/src/core/render/Render.js +++ b/simple-mind-map/src/core/render/Render.js @@ -824,6 +824,8 @@ class Render { if (this.activeNodeList.length <= 0 && appointNodes.length <= 0) { return } + // 删除节点后需要激活的节点 + let needActiveNode = null let isAppointNodes = appointNodes.length > 0 let list = isAppointNodes ? appointNodes : this.activeNodeList let root = list.find(node => { @@ -837,6 +839,27 @@ class Render { root.children = [] root.nodeData.children = [] } else { + // 如果只选中了一个节点,删除后激活其兄弟节点或者父节点 + if ( + this.activeNodeList.length === 1 && + !this.activeNodeList[0].isGeneralization&&this.mindMap.opt.deleteNodeActive + ) { + const node = this.activeNodeList[0] + const broList = node.parent.children + const nodeIndex = broList.findIndex(item => item.uid === node.uid) + // 如果后面有兄弟节点 + if (nodeIndex < broList.length - 1) { + needActiveNode = broList[nodeIndex + 1] + } else { + // 如果前面有兄弟节点 + if (nodeIndex > 0) { + needActiveNode = broList[nodeIndex - 1] + } else { + // 没有兄弟节点 + needActiveNode = node.parent + } + } + } for (let i = 0; i < list.length; i++) { let node = list[i] if (isAppointNodes) list.splice(i, 1) @@ -855,6 +878,13 @@ class Render { } } } + this.activeNodeList = [] + // 激活被删除节点的兄弟节点或父节点 + if (needActiveNode) { + this.activeNodeList.push(needActiveNode) + this.setNodeActive(needActiveNode, true) + needActiveNode = null + } this.mindMap.emit('node_active', null, [...this.activeNodeList]) this.mindMap.render() }