diff --git a/simple-mind-map/src/constants/defaultOptions.js b/simple-mind-map/src/constants/defaultOptions.js index 1f5d91ef..44c5a919 100644 --- a/simple-mind-map/src/constants/defaultOptions.js +++ b/simple-mind-map/src/constants/defaultOptions.js @@ -173,8 +173,8 @@ export const defaultOpt = { box-sizing: border-box; } `, - // 开启鼠标双击复位思维导图位置及缩放 - enableDblclickReset: false, + // 是否在鼠标双击时回到根节点,也就是让根节点居中显示 + enableDblclickBackToRootNode: false, // 导出图片时canvas的缩放倍数,该配置会和window.devicePixelRatio值取最大值 minExportImgCanvasScale: 2, // 节点鼠标hover和激活时显示的矩形边框的颜色 diff --git a/simple-mind-map/src/core/render/Render.js b/simple-mind-map/src/core/render/Render.js index f954e08d..45e2b91a 100644 --- a/simple-mind-map/src/core/render/Render.js +++ b/simple-mind-map/src/core/render/Render.js @@ -122,6 +122,11 @@ class Render { this.mindMap.execCommand('CLEAR_ACTIVE_NODE') } }) + // 鼠标双击回到根节点 + this.mindMap.svg.on('dblclick', () => { + if (!this.mindMap.opt.enableDblclickBackToRootNode) return + this.setRootNodeCenter() + }) // let timer = null // this.mindMap.on('view_data_change', () => { // clearTimeout(timer) @@ -299,6 +304,10 @@ class Render { }) this.cut = this.cut.bind(this) this.mindMap.keyCommand.addShortcut('Control+x', this.cut) + // 根节点居中显示 + this.mindMap.keyCommand.addShortcut('Control+Enter', () => { + this.setRootNodeCenter() + }) } // 开启文字编辑,会禁用回车键和删除键相关快捷键防止冲突 @@ -557,12 +566,11 @@ class Render { const index = parent.nodeData.children.findIndex(item => { return item.data.uid === node.uid }) - const newNodeList = createUidForAppointNodes(simpleDeepClone(nodeList), true) - parent.nodeData.children.splice( - index + 1, - 0, - ...newNodeList + const newNodeList = createUidForAppointNodes( + simpleDeepClone(nodeList), + true ) + parent.nodeData.children.splice(index + 1, 0, ...newNodeList) }) Object.keys(needDestroyNodeList).forEach(key => { needDestroyNodeList[key].destroy() @@ -1432,6 +1440,11 @@ class Render { this.mindMap.view.setScale(1) } + // 回到中心主题,即设置根节点到画布中心 + setRootNodeCenter() { + this.moveNodeToCenter(this.root) + } + // 展开到指定uid的节点 expandToNodeUid(uid, callback = () => {}) { let parentsList = [] diff --git a/simple-mind-map/src/core/view/View.js b/simple-mind-map/src/core/view/View.js index c318da0d..853f9d14 100644 --- a/simple-mind-map/src/core/view/View.js +++ b/simple-mind-map/src/core/view/View.js @@ -25,16 +25,9 @@ class View { this.mindMap.keyCommand.addShortcut('Control+-', () => { this.narrow() }) - this.mindMap.keyCommand.addShortcut('Control+Enter', () => { - this.reset() - }) this.mindMap.keyCommand.addShortcut('Control+i', () => { this.fit() }) - this.mindMap.svg.on('dblclick', () => { - if (!this.mindMap.opt.enableDblclickReset) return - this.reset() - }) // 拖动视图 this.mindMap.event.on('mousedown', () => { this.sx = this.x