Fix:修复只读模式下搜索节点的高亮不会消失的问题
This commit is contained in:
parent
79ccd9892c
commit
43969af14b
@ -410,7 +410,9 @@ class MindMap {
|
|||||||
if (![CONSTANTS.MODE.READONLY, CONSTANTS.MODE.EDIT].includes(mode)) {
|
if (![CONSTANTS.MODE.READONLY, CONSTANTS.MODE.EDIT].includes(mode)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.opt.readonly = mode === CONSTANTS.MODE.READONLY
|
const isReadonly = mode === CONSTANTS.MODE.READONLY
|
||||||
|
if (isReadonly === this.opt.readonly) return
|
||||||
|
this.opt.readonly = isReadonly
|
||||||
if (this.opt.readonly) {
|
if (this.opt.readonly) {
|
||||||
// 取消当前激活的元素
|
// 取消当前激活的元素
|
||||||
this.execCommand('CLEAR_ACTIVE_NODE')
|
this.execCommand('CLEAR_ACTIVE_NODE')
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import {
|
|||||||
replaceHtmlText
|
replaceHtmlText
|
||||||
} from '../utils/index'
|
} from '../utils/index'
|
||||||
import Node from '../core/render/node/Node'
|
import Node from '../core/render/node/Node'
|
||||||
|
import { CONSTANTS } from '../constants/constant'
|
||||||
|
|
||||||
// 搜索插件
|
// 搜索插件
|
||||||
class Search {
|
class Search {
|
||||||
@ -29,11 +30,14 @@ class Search {
|
|||||||
|
|
||||||
bindEvent() {
|
bindEvent() {
|
||||||
this.onDataChange = this.onDataChange.bind(this)
|
this.onDataChange = this.onDataChange.bind(this)
|
||||||
|
this.onModeChange = this.onModeChange.bind(this)
|
||||||
this.mindMap.on('data_change', this.onDataChange)
|
this.mindMap.on('data_change', this.onDataChange)
|
||||||
|
this.mindMap.on('mode_change', this.onModeChange)
|
||||||
}
|
}
|
||||||
|
|
||||||
unBindEvent() {
|
unBindEvent() {
|
||||||
this.mindMap.off('data_change', this.onDataChange)
|
this.mindMap.off('data_change', this.onDataChange)
|
||||||
|
this.mindMap.off('mode_change', this.onModeChange)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 节点数据改变了,需要重新搜索
|
// 节点数据改变了,需要重新搜索
|
||||||
@ -50,6 +54,19 @@ class Search {
|
|||||||
this.searchText = ''
|
this.searchText = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 监听只读模式切换
|
||||||
|
onModeChange(mode) {
|
||||||
|
const isReadonly = mode === CONSTANTS.MODE.READONLY
|
||||||
|
// 如果是由只读模式切换为非只读模式,需要清除只读模式下的节点高亮
|
||||||
|
if (
|
||||||
|
!isReadonly &&
|
||||||
|
this.isSearching &&
|
||||||
|
this.matchNodeList[this.currentIndex]
|
||||||
|
) {
|
||||||
|
this.matchNodeList[this.currentIndex].closeHighlight()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 搜索
|
// 搜索
|
||||||
search(text, callback = () => {}) {
|
search(text, callback = () => {}) {
|
||||||
if (isUndef(text)) return this.endSearch()
|
if (isUndef(text)) return this.endSearch()
|
||||||
@ -117,6 +134,15 @@ class Search {
|
|||||||
} else {
|
} else {
|
||||||
this.currentIndex = 0
|
this.currentIndex = 0
|
||||||
}
|
}
|
||||||
|
const { readonly } = this.mindMap.opt
|
||||||
|
// 只读模式下需要激活之前节点的高亮
|
||||||
|
if (readonly) {
|
||||||
|
this.matchNodeList.forEach(node => {
|
||||||
|
if (this.isNodeInstance(node)) {
|
||||||
|
node.closeHighlight()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
const currentNode = this.matchNodeList[this.currentIndex]
|
const currentNode = this.matchNodeList[this.currentIndex]
|
||||||
this.notResetSearchText = true
|
this.notResetSearchText = true
|
||||||
const uid = this.isNodeInstance(currentNode)
|
const uid = this.isNodeInstance(currentNode)
|
||||||
@ -129,7 +155,7 @@ class Search {
|
|||||||
}
|
}
|
||||||
callback()
|
callback()
|
||||||
// 只读模式下节点无法激活,所以通过高亮的方式
|
// 只读模式下节点无法激活,所以通过高亮的方式
|
||||||
if (this.mindMap.opt.readonly) {
|
if (readonly) {
|
||||||
node.highlight()
|
node.highlight()
|
||||||
}
|
}
|
||||||
// 如果当前节点实例已经存在,则不会触发data_change事件,那么需要手动把标志复位
|
// 如果当前节点实例已经存在,则不会触发data_change事件,那么需要手动把标志复位
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user