修复超链接、备注、标签等文字编辑时返回键和回车键与思维导图快捷键冲突的问题

This commit is contained in:
wanglin25
2022-05-09 11:03:56 +08:00
parent c3f4e2b797
commit 25a2d919fb
8 changed files with 54 additions and 12 deletions

View File

@@ -250,7 +250,7 @@ const mindMap = new MindMap({
`data`:思维导图结构数据
#### export(type, isDownload)
#### export(type, isDownload, fileName)
导出
@@ -258,6 +258,8 @@ const mindMap = new MindMap({
`isDownload`:是否需要直接触发下载,布尔值,默认为`false`
`fileName`v0.1.6+)导出文件的名称,默认为`思维导图`
#### toPos(x, y)
v0.1.5+
@@ -286,6 +288,14 @@ v0.1.5+
### 方法
#### startTextEdit()
v0.1.6+)若有文字编辑需求可调用该方法,会禁用回车键和删除键相关快捷键防止冲突
#### endTextEdit()
v0.1.6+)结束文字编辑,会恢复回车键和删除键相关快捷键
#### addActiveNode(node)
添加节点到激活列表里

View File

@@ -22,11 +22,11 @@ class Export {
* @Date: 2021-07-02 07:44:06
* @Desc: 导出
*/
async export(type, isDownload = true) {
async export(type, isDownload = true, name = '思维导图') {
if (this[type]) {
let result = await this[type]()
if (isDownload) {
downloadFile(result, '思维导图.' + type)
downloadFile(result, name + '.' + type)
}
return result
} else {

View File

@@ -176,13 +176,13 @@ class Render {
this.mindMap.execCommand('INSERT_CHILD_NODE')
})
// 插入同级节点
let insertNodeWrap = () => {
this.insertNodeWrap = () => {
if (this.textEdit.showTextEdit) {
return
}
this.mindMap.execCommand('INSERT_NODE')
}
this.mindMap.keyCommand.addShortcut('Enter', insertNodeWrap)
this.mindMap.keyCommand.addShortcut('Enter', this.insertNodeWrap)
// 展开/收起节点
this.mindMap.keyCommand.addShortcut('/', () => {
this.activeNodeList.forEach((node) => {
@@ -193,18 +193,16 @@ class Render {
})
})
// 删除节点
let removeNodeWrap = () => {
this.removeNodeWrap = () => {
this.mindMap.execCommand('REMOVE_NODE')
}
this.mindMap.keyCommand.addShortcut('Del|Backspace', removeNodeWrap)
this.mindMap.keyCommand.addShortcut('Del|Backspace', this.removeNodeWrap)
// 节点编辑时某些快捷键会存在冲突,需要暂时去除
this.mindMap.on('before_show_text_edit', () => {
this.mindMap.keyCommand.removeShortcut('Del|Backspace')
this.mindMap.keyCommand.removeShortcut('Enter', insertNodeWrap)
this.startTextEdit()
})
this.mindMap.on('hide_text_edit', () => {
this.mindMap.keyCommand.addShortcut('Del|Backspace', removeNodeWrap)
this.mindMap.keyCommand.addShortcut('Enter', insertNodeWrap)
this.endTextEdit()
})
// 全选
this.mindMap.keyCommand.addShortcut('Control+a', () => {
@@ -212,6 +210,28 @@ class Render {
})
}
/**
* javascript comment
* @Author: 王林25
* @Date: 2022-05-09 10:43:52
* @Desc: 开启文字编辑,会禁用回车键和删除键相关快捷键防止冲突
*/
startTextEdit() {
this.mindMap.keyCommand.removeShortcut('Del|Backspace')
this.mindMap.keyCommand.removeShortcut('Enter', this.insertNodeWrap)
}
/**
* javascript comment
* @Author: 王林25
* @Date: 2022-05-09 10:45:11
* @Desc: 结束文字编辑,会恢复回车键和删除键相关快捷键
*/
endTextEdit() {
this.mindMap.keyCommand.addShortcut('Del|Backspace', this.removeNodeWrap)
this.mindMap.keyCommand.addShortcut('Enter', this.insertNodeWrap)
}
/**
* javascript comment
* @Author: 王林25

View File

@@ -58,6 +58,12 @@ export default {
this.$bus.$on('execCommand', this.execCommand)
this.$bus.$on('export', this.export)
this.$bus.$on('setData', this.setData)
this.$bus.$on('startTextEdit', () => {
this.mindMap.renderer.startTextEdit();
});
this.$bus.$on('endTextEdit', () => {
this.mindMap.renderer.endTextEdit();
});
if (this.openTest) {
setTimeout(() => {
this.test()

View File

@@ -61,7 +61,7 @@ export default {
* @Desc: 确定
*/
confirm() {
this.$bus.$emit("export", this.exportType);
this.$bus.$emit("export", this.exportType, true, this.fileName);
this.$notify.info({
title: '消息',
message: '如果没有触发下载,请检查是否被浏览器拦截了'

View File

@@ -53,6 +53,7 @@ export default {
}
});
this.$bus.$on("showNodeLink", () => {
this.$bus.$emit('startTextEdit');
this.dialogVisible = true;
});
},
@@ -64,6 +65,7 @@ export default {
*/
cancel() {
this.dialogVisible = false;
this.$bus.$emit('endTextEdit');
},
/**

View File

@@ -46,6 +46,7 @@ export default {
}
});
this.$bus.$on("showNodeNote", () => {
this.$bus.$emit('startTextEdit');
this.dialogVisible = true;
});
},
@@ -57,6 +58,7 @@ export default {
*/
cancel() {
this.dialogVisible = false;
this.$bus.$emit('endTextEdit');
},
/**

View File

@@ -67,6 +67,7 @@ export default {
}
});
this.$bus.$on("showNodeTag", () => {
this.$bus.$emit('startTextEdit');
this.dialogVisible = true;
});
},
@@ -97,6 +98,7 @@ export default {
*/
cancel() {
this.dialogVisible = false;
this.$bus.$emit('endTextEdit');
},
/**