From 7a2075df513690190351f42dfa0a34393d05de72 Mon Sep 17 00:00:00 2001 From: wanglin2 <1013335014@qq.com> Date: Tue, 16 Aug 2022 16:47:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E6=96=87=E6=9C=AC=E6=97=B6=E5=BF=AB=E6=8D=B7?= =?UTF-8?q?=E9=94=AE=E5=86=B2=E7=AA=81=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 10 ++++++++++ index.html | 2 +- simple-mind-map/package.json | 2 +- simple-mind-map/src/KeyCommand.js | 23 +++++++++++++++++++++++ simple-mind-map/src/Render.js | 18 ++++++++++-------- simple-mind-map/src/TextEdit.js | 18 ++++++++++++++---- web/src/config/index.js | 4 ++-- 7 files changed, 61 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 448bfe16..8f8f899c 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,8 @@ npm run build # 安装 +> 当然仓库版本:0.2.3,当前npm版本:0.2.2 + ```bash npm i simple-mind-map ``` @@ -452,6 +454,14 @@ v0.2.2+。暂停所有快捷键响应 v0.2.2+。恢复快捷键响应 +#### save() + +v0.2.3+。保存当前注册的快捷键数据,然后清空快捷键数据 + +#### restore() + +v0.2.3+。恢复保存的快捷键数据,然后清空缓存数据 + ## command实例 diff --git a/index.html b/index.html index efe46bab..cbd5af0a 100644 --- a/index.html +++ b/index.html @@ -1 +1 @@ -一个简单的web思维导图实现
\ No newline at end of file +一个简单的web思维导图实现
\ No newline at end of file diff --git a/simple-mind-map/package.json b/simple-mind-map/package.json index e7d80628..481dffd6 100644 --- a/simple-mind-map/package.json +++ b/simple-mind-map/package.json @@ -1,6 +1,6 @@ { "name": "simple-mind-map", - "version": "0.2.2", + "version": "0.2.3", "description": "一个简单的web在线思维导图", "authors": [ { diff --git a/simple-mind-map/src/KeyCommand.js b/simple-mind-map/src/KeyCommand.js index 6b31ee21..c152a487 100644 --- a/simple-mind-map/src/KeyCommand.js +++ b/simple-mind-map/src/KeyCommand.js @@ -16,6 +16,7 @@ export default class KeyCommand { this.shortcutMap = { //Enter: [fn] } + this.shortcutMapCache = {} this.isPause = false this.bindEvent() } @@ -38,6 +39,28 @@ export default class KeyCommand { this.isPause = false } + /** + * javascript comment + * @Author: 王林25 + * @Date: 2022-08-16 16:29:01 + * @Desc: 保存当前注册的快捷键数据,然后清空快捷键数据 + */ + save() { + this.shortcutMapCache = this.shortcutMap + this.shortcutMap = {} + } + + /** + * javascript comment + * @Author: 王林25 + * @Date: 2022-08-16 16:29:38 + * @Desc: 恢复保存的快捷键数据,然后清空缓存数据 + */ + restore() { + this.shortcutMap = this.shortcutMapCache + this.shortcutMapCache = {} + } + /** * @Author: 王林 * @Date: 2021-04-24 15:23:22 diff --git a/simple-mind-map/src/Render.js b/simple-mind-map/src/Render.js index 18dab112..57e97e4f 100644 --- a/simple-mind-map/src/Render.js +++ b/simple-mind-map/src/Render.js @@ -196,7 +196,7 @@ class Render { } this.mindMap.keyCommand.addShortcut('Enter', this.insertNodeWrap) // 插入概要 - this.mindMap.keyCommand.addShortcut('Shift+s', this.addGeneralization) + this.mindMap.keyCommand.addShortcut('Control+s', this.addGeneralization) // 展开/收起节点 this.toggleActiveExpand = this.toggleActiveExpand.bind(this) this.mindMap.keyCommand.addShortcut('/', this.toggleActiveExpand) @@ -217,7 +217,7 @@ class Render { this.mindMap.execCommand('SELECT_ALL') }) // 一键整理布局 - this.mindMap.keyCommand.addShortcut('Shift+l', this.resetLayout) + this.mindMap.keyCommand.addShortcut('Control+l', this.resetLayout) // 上移节点 this.mindMap.keyCommand.addShortcut('Control+Up', this.upNode) // 下移节点 @@ -232,9 +232,10 @@ class Render { * @Desc: 开启文字编辑,会禁用回车键和删除键相关快捷键防止冲突 */ startTextEdit() { - this.mindMap.keyCommand.removeShortcut('Del|Backspace') - this.mindMap.keyCommand.removeShortcut('/') - this.mindMap.keyCommand.removeShortcut('Enter', this.insertNodeWrap) + this.mindMap.keyCommand.save() + // this.mindMap.keyCommand.removeShortcut('Del|Backspace') + // this.mindMap.keyCommand.removeShortcut('/') + // this.mindMap.keyCommand.removeShortcut('Enter', this.insertNodeWrap) } /** @@ -244,9 +245,10 @@ class Render { * @Desc: 结束文字编辑,会恢复回车键和删除键相关快捷键 */ endTextEdit() { - this.mindMap.keyCommand.addShortcut('Del|Backspace', this.removeNodeWrap) - this.mindMap.keyCommand.addShortcut('/', this.toggleActiveExpand) - this.mindMap.keyCommand.addShortcut('Enter', this.insertNodeWrap) + this.mindMap.keyCommand.restore() + // this.mindMap.keyCommand.addShortcut('Del|Backspace', this.removeNodeWrap) + // this.mindMap.keyCommand.addShortcut('/', this.toggleActiveExpand) + // this.mindMap.keyCommand.addShortcut('Enter', this.insertNodeWrap) } /** diff --git a/simple-mind-map/src/TextEdit.js b/simple-mind-map/src/TextEdit.js index f9c42ae0..f80d35af 100644 --- a/simple-mind-map/src/TextEdit.js +++ b/simple-mind-map/src/TextEdit.js @@ -47,10 +47,6 @@ export default class TextEdit { this.mindMap.on('before_node_active', () => { this.hideEditTextBox() }) - // 注册回车快捷键 - this.mindMap.keyCommand.addShortcut('Enter', () => { - this.hideEditTextBox() - }) // 注册编辑快捷键 this.mindMap.keyCommand.addShortcut('F2', () => { if (this.renderer.activeNodeList.length <= 0) { @@ -60,6 +56,19 @@ export default class TextEdit { }) } + /** + * javascript comment + * @Author: 王林25 + * @Date: 2022-08-16 16:27:02 + * @Desc: 注册临时快捷键 + */ + registerTmpShortcut() { + // 注册回车快捷键 + this.mindMap.keyCommand.addShortcut('Enter', () => { + this.hideEditTextBox() + }) + } + /** * @Author: 王林 * @Date: 2021-04-13 22:15:56 @@ -76,6 +85,7 @@ export default class TextEdit { */ showEditTextBox(node, rect) { this.mindMap.emit('before_show_text_edit') + this.registerTmpShortcut() if (!this.textEditNode) { this.textEditNode = document.createElement('div') this.textEditNode.style.cssText = `position:fixed;box-sizing: border-box;background-color:#fff;box-shadow: 0 0 20px rgba(0,0,0,.5);padding: 3px 5px;margin-left: -5px;margin-top: -3px;outline: none;` diff --git a/web/src/config/index.js b/web/src/config/index.js index e69498fb..f374b38a 100644 --- a/web/src/config/index.js +++ b/web/src/config/index.js @@ -227,7 +227,7 @@ export const shortcutKeyList = [ { icon: 'icongaikuozonglan', name: '插入概要', - value: 'Shift + S' + value: 'Ctrl + S' }, { icon: 'iconzhankai', @@ -287,7 +287,7 @@ export const shortcutKeyList = [ { icon: 'iconzhengli', name: '一键整理布局', - value: 'Shift + L' + value: 'Ctrl + L' }, ] },