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() }