Fix:修复非富文本模式下新建节点操作撤回也需要两次的问题
This commit is contained in:
parent
af752ea761
commit
cd28be4b01
@ -124,7 +124,7 @@ class Render {
|
|||||||
|
|
||||||
// 重新设置思维导图数据
|
// 重新设置思维导图数据
|
||||||
setData(data) {
|
setData(data) {
|
||||||
if (this.mindMap.richText) {
|
if (this.hasRichTextPlugin()) {
|
||||||
this.renderTree = data ? this.mindMap.richText.handleSetData(data) : null
|
this.renderTree = data ? this.mindMap.richText.handleSetData(data) : null
|
||||||
} else {
|
} else {
|
||||||
this.renderTree = data
|
this.renderTree = data
|
||||||
@ -546,7 +546,7 @@ class Render {
|
|||||||
}
|
}
|
||||||
// 触发一次保存,因为修改了渲染树的数据
|
// 触发一次保存,因为修改了渲染树的数据
|
||||||
if (
|
if (
|
||||||
this.mindMap.richText &&
|
this.hasRichTextPlugin() &&
|
||||||
[CONSTANTS.CHANGE_THEME, CONSTANTS.SET_DATA].includes(source)
|
[CONSTANTS.CHANGE_THEME, CONSTANTS.SET_DATA].includes(source)
|
||||||
) {
|
) {
|
||||||
this.mindMap.command.addHistory()
|
this.mindMap.command.addHistory()
|
||||||
@ -560,7 +560,7 @@ class Render {
|
|||||||
|
|
||||||
// 给当前被收起来的节点数据添加文本复位标志
|
// 给当前被收起来的节点数据添加文本复位标志
|
||||||
resetUnExpandNodeStyle() {
|
resetUnExpandNodeStyle() {
|
||||||
if (!this.renderTree) return
|
if (!this.renderTree || !this.hasRichTextPlugin()) return
|
||||||
walk(this.renderTree, null, node => {
|
walk(this.renderTree, null, node => {
|
||||||
if (!node.data.expand) {
|
if (!node.data.expand) {
|
||||||
walk(node, null, node2 => {
|
walk(node, null, node2 => {
|
||||||
@ -737,7 +737,7 @@ class Render {
|
|||||||
} = this.mindMap.opt
|
} = this.mindMap.opt
|
||||||
const list = appointNodes.length > 0 ? appointNodes : this.activeNodeList
|
const list = appointNodes.length > 0 ? appointNodes : this.activeNodeList
|
||||||
const handleMultiNodes = list.length > 1
|
const handleMultiNodes = list.length > 1
|
||||||
const isRichText = !!this.mindMap.richText
|
const isRichText = this.hasRichTextPlugin()
|
||||||
const { focusNewNode, inserting } = this.getNewNodeBehavior(
|
const { focusNewNode, inserting } = this.getNewNodeBehavior(
|
||||||
openEdit,
|
openEdit,
|
||||||
handleMultiNodes
|
handleMultiNodes
|
||||||
@ -745,9 +745,9 @@ class Render {
|
|||||||
const params = {
|
const params = {
|
||||||
expand: true,
|
expand: true,
|
||||||
richText: isRichText,
|
richText: isRichText,
|
||||||
resetRichText: isRichText,
|
|
||||||
isActive: focusNewNode // 如果同时对多个节点插入子节点,那么需要把新增的节点设为激活状态。如果不进入编辑状态,那么也需要手动设为激活状态
|
isActive: focusNewNode // 如果同时对多个节点插入子节点,那么需要把新增的节点设为激活状态。如果不进入编辑状态,那么也需要手动设为激活状态
|
||||||
}
|
}
|
||||||
|
if (isRichText) params.resetRichText = isRichText
|
||||||
// 动态指定的子节点数据也需要添加相关属性
|
// 动态指定的子节点数据也需要添加相关属性
|
||||||
appointChildren = addDataToAppointNodes(appointChildren, {
|
appointChildren = addDataToAppointNodes(appointChildren, {
|
||||||
...params
|
...params
|
||||||
@ -792,14 +792,14 @@ class Render {
|
|||||||
}
|
}
|
||||||
this.textEdit.hideEditTextBox()
|
this.textEdit.hideEditTextBox()
|
||||||
const list = appointNodes.length > 0 ? appointNodes : this.activeNodeList
|
const list = appointNodes.length > 0 ? appointNodes : this.activeNodeList
|
||||||
const isRichText = !!this.mindMap.richText
|
const isRichText = this.hasRichTextPlugin()
|
||||||
const { focusNewNode } = this.getNewNodeBehavior(false, true)
|
const { focusNewNode } = this.getNewNodeBehavior(false, true)
|
||||||
const params = {
|
const params = {
|
||||||
expand: true,
|
expand: true,
|
||||||
richText: isRichText,
|
richText: isRichText,
|
||||||
resetRichText: isRichText,
|
|
||||||
isActive: focusNewNode
|
isActive: focusNewNode
|
||||||
}
|
}
|
||||||
|
if (isRichText) params.resetRichText = isRichText
|
||||||
nodeList = addDataToAppointNodes(nodeList, params)
|
nodeList = addDataToAppointNodes(nodeList, params)
|
||||||
list.forEach(node => {
|
list.forEach(node => {
|
||||||
if (node.isGeneralization || node.isRoot) {
|
if (node.isGeneralization || node.isRoot) {
|
||||||
@ -835,7 +835,7 @@ class Render {
|
|||||||
} = this.mindMap.opt
|
} = this.mindMap.opt
|
||||||
const list = appointNodes.length > 0 ? appointNodes : this.activeNodeList
|
const list = appointNodes.length > 0 ? appointNodes : this.activeNodeList
|
||||||
const handleMultiNodes = list.length > 1
|
const handleMultiNodes = list.length > 1
|
||||||
const isRichText = !!this.mindMap.richText
|
const isRichText = this.hasRichTextPlugin()
|
||||||
const { focusNewNode, inserting } = this.getNewNodeBehavior(
|
const { focusNewNode, inserting } = this.getNewNodeBehavior(
|
||||||
openEdit,
|
openEdit,
|
||||||
handleMultiNodes
|
handleMultiNodes
|
||||||
@ -843,9 +843,9 @@ class Render {
|
|||||||
const params = {
|
const params = {
|
||||||
expand: true,
|
expand: true,
|
||||||
richText: isRichText,
|
richText: isRichText,
|
||||||
resetRichText: isRichText,
|
|
||||||
isActive: focusNewNode
|
isActive: focusNewNode
|
||||||
}
|
}
|
||||||
|
if (isRichText) params.resetRichText = isRichText
|
||||||
// 动态指定的子节点数据也需要添加相关属性
|
// 动态指定的子节点数据也需要添加相关属性
|
||||||
appointChildren = addDataToAppointNodes(appointChildren, {
|
appointChildren = addDataToAppointNodes(appointChildren, {
|
||||||
...params
|
...params
|
||||||
@ -892,14 +892,14 @@ class Render {
|
|||||||
}
|
}
|
||||||
this.textEdit.hideEditTextBox()
|
this.textEdit.hideEditTextBox()
|
||||||
const list = appointNodes.length > 0 ? appointNodes : this.activeNodeList
|
const list = appointNodes.length > 0 ? appointNodes : this.activeNodeList
|
||||||
const isRichText = !!this.mindMap.richText
|
const isRichText = this.hasRichTextPlugin()
|
||||||
const { focusNewNode } = this.getNewNodeBehavior(false, true)
|
const { focusNewNode } = this.getNewNodeBehavior(false, true)
|
||||||
const params = {
|
const params = {
|
||||||
expand: true,
|
expand: true,
|
||||||
richText: isRichText,
|
richText: isRichText,
|
||||||
resetRichText: isRichText,
|
|
||||||
isActive: focusNewNode
|
isActive: focusNewNode
|
||||||
}
|
}
|
||||||
|
if (isRichText) params.resetRichText = isRichText
|
||||||
childList = addDataToAppointNodes(childList, params)
|
childList = addDataToAppointNodes(childList, params)
|
||||||
list.forEach(node => {
|
list.forEach(node => {
|
||||||
if (node.isGeneralization) {
|
if (node.isGeneralization) {
|
||||||
@ -934,7 +934,7 @@ class Render {
|
|||||||
} = this.mindMap.opt
|
} = this.mindMap.opt
|
||||||
const list = appointNodes.length > 0 ? appointNodes : this.activeNodeList
|
const list = appointNodes.length > 0 ? appointNodes : this.activeNodeList
|
||||||
const handleMultiNodes = list.length > 1
|
const handleMultiNodes = list.length > 1
|
||||||
const isRichText = !!this.mindMap.richText
|
const isRichText = this.hasRichTextPlugin()
|
||||||
const { focusNewNode, inserting } = this.getNewNodeBehavior(
|
const { focusNewNode, inserting } = this.getNewNodeBehavior(
|
||||||
openEdit,
|
openEdit,
|
||||||
handleMultiNodes
|
handleMultiNodes
|
||||||
@ -942,9 +942,9 @@ class Render {
|
|||||||
const params = {
|
const params = {
|
||||||
expand: true,
|
expand: true,
|
||||||
richText: isRichText,
|
richText: isRichText,
|
||||||
resetRichText: isRichText,
|
|
||||||
isActive: focusNewNode
|
isActive: focusNewNode
|
||||||
}
|
}
|
||||||
|
if (isRichText) params.resetRichText = isRichText
|
||||||
list.forEach(node => {
|
list.forEach(node => {
|
||||||
if (node.isGeneralization || node.isRoot) {
|
if (node.isGeneralization || node.isRoot) {
|
||||||
return
|
return
|
||||||
@ -963,9 +963,11 @@ class Render {
|
|||||||
},
|
},
|
||||||
children: [node.nodeData]
|
children: [node.nodeData]
|
||||||
}
|
}
|
||||||
node.setData({
|
if (isRichText) {
|
||||||
resetRichText: true
|
node.setData({
|
||||||
})
|
resetRichText: true
|
||||||
|
})
|
||||||
|
}
|
||||||
const parent = node.parent
|
const parent = node.parent
|
||||||
// 获取当前节点所在位置
|
// 获取当前节点所在位置
|
||||||
const index = getNodeDataIndex(node)
|
const index = getNodeDataIndex(node)
|
||||||
@ -1055,7 +1057,7 @@ class Render {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
// 如果是富文本,那么还要处理富文本内容
|
// 如果是富文本,那么还要处理富文本内容
|
||||||
if (hasCustomStyles && this.mindMap.richText) {
|
if (hasCustomStyles && this.hasRichTextPlugin()) {
|
||||||
nodeData.resetRichText = true
|
nodeData.resetRichText = true
|
||||||
nodeData.text = removeRichTextStyes(nodeData.text)
|
nodeData.text = removeRichTextStyes(nodeData.text)
|
||||||
}
|
}
|
||||||
@ -1339,7 +1341,7 @@ class Render {
|
|||||||
|
|
||||||
// 如果是富文本模式,那么某些层级变化需要更新样式
|
// 如果是富文本模式,那么某些层级变化需要更新样式
|
||||||
checkNodeLayerChange(node, toNode, toNodeIsParent = false) {
|
checkNodeLayerChange(node, toNode, toNodeIsParent = false) {
|
||||||
if (this.mindMap.richText) {
|
if (this.hasRichTextPlugin()) {
|
||||||
// 如果设置了自定义样式那么不需要更新
|
// 如果设置了自定义样式那么不需要更新
|
||||||
if (this.mindMap.richText.checkNodeHasCustomRichTextStyle(node)) {
|
if (this.mindMap.richText.checkNodeHasCustomRichTextStyle(node)) {
|
||||||
return
|
return
|
||||||
@ -1566,7 +1568,7 @@ class Render {
|
|||||||
const newData = simpleDeepClone(item)
|
const newData = simpleDeepClone(item)
|
||||||
createUidForAppointNodes([newData], true, node => {
|
createUidForAppointNodes([newData], true, node => {
|
||||||
// 可能跨层级复制,那么富文本样式需要更新
|
// 可能跨层级复制,那么富文本样式需要更新
|
||||||
if (this.mindMap.richText) {
|
if (this.hasRichTextPlugin()) {
|
||||||
// 如果设置了自定义样式那么不需要更新
|
// 如果设置了自定义样式那么不需要更新
|
||||||
if (
|
if (
|
||||||
this.mindMap.richText.checkNodeHasCustomRichTextStyle(node.data)
|
this.mindMap.richText.checkNodeHasCustomRichTextStyle(node.data)
|
||||||
@ -1589,7 +1591,7 @@ class Render {
|
|||||||
[prop]: value
|
[prop]: value
|
||||||
}
|
}
|
||||||
// 如果开启了富文本,则需要应用到富文本上
|
// 如果开启了富文本,则需要应用到富文本上
|
||||||
if (this.mindMap.richText) {
|
if (this.hasRichTextPlugin()) {
|
||||||
this.mindMap.richText.setNotActiveNodeStyle(node, {
|
this.mindMap.richText.setNotActiveNodeStyle(node, {
|
||||||
[prop]: value
|
[prop]: value
|
||||||
})
|
})
|
||||||
@ -1605,7 +1607,7 @@ class Render {
|
|||||||
setNodeStyles(node, style) {
|
setNodeStyles(node, style) {
|
||||||
let data = { ...style }
|
let data = { ...style }
|
||||||
// 如果开启了富文本,则需要应用到富文本上
|
// 如果开启了富文本,则需要应用到富文本上
|
||||||
if (this.mindMap.richText) {
|
if (this.hasRichTextPlugin()) {
|
||||||
this.mindMap.richText.setNotActiveNodeStyle(node, style)
|
this.mindMap.richText.setNotActiveNodeStyle(node, style)
|
||||||
}
|
}
|
||||||
this.setNodeDataRender(node, data)
|
this.setNodeDataRender(node, data)
|
||||||
@ -1800,7 +1802,7 @@ class Render {
|
|||||||
// 设置节点公式
|
// 设置节点公式
|
||||||
insertFormula(formula, appointNodes = []) {
|
insertFormula(formula, appointNodes = []) {
|
||||||
// 只在富文本模式下可用,并且需要注册Formula插件
|
// 只在富文本模式下可用,并且需要注册Formula插件
|
||||||
if (!this.mindMap.richText || !this.mindMap.formula) return
|
if (!this.hasRichTextPlugin() || !this.mindMap.formula) return
|
||||||
appointNodes = formatDataToArray(appointNodes)
|
appointNodes = formatDataToArray(appointNodes)
|
||||||
const list = appointNodes.length > 0 ? appointNodes : this.activeNodeList
|
const list = appointNodes.length > 0 ? appointNodes : this.activeNodeList
|
||||||
list.forEach(node => {
|
list.forEach(node => {
|
||||||
@ -1822,7 +1824,7 @@ class Render {
|
|||||||
})
|
})
|
||||||
const list = parseAddGeneralizationNodeList(nodeList)
|
const list = parseAddGeneralizationNodeList(nodeList)
|
||||||
if (list.length <= 0) return
|
if (list.length <= 0) return
|
||||||
const isRichText = !!this.mindMap.richText
|
const isRichText = this.hasRichTextPlugin()
|
||||||
const { focusNewNode, inserting } = this.getNewNodeBehavior(
|
const { focusNewNode, inserting } = this.getNewNodeBehavior(
|
||||||
openEdit,
|
openEdit,
|
||||||
list.length > 1
|
list.length > 1
|
||||||
@ -1837,9 +1839,9 @@ class Render {
|
|||||||
range: item.range || null,
|
range: item.range || null,
|
||||||
uid: createUid(),
|
uid: createUid(),
|
||||||
richText: isRichText,
|
richText: isRichText,
|
||||||
resetRichText: isRichText,
|
|
||||||
isActive: focusNewNode
|
isActive: focusNewNode
|
||||||
}
|
}
|
||||||
|
if (isRichText) newData.resetRichText = isRichText
|
||||||
let generalization = item.node.getData('generalization')
|
let generalization = item.node.getData('generalization')
|
||||||
generalization = generalization
|
generalization = generalization
|
||||||
? Array.isArray(generalization)
|
? Array.isArray(generalization)
|
||||||
@ -2169,6 +2171,11 @@ class Render {
|
|||||||
if (!this.highlightBoxNode) return
|
if (!this.highlightBoxNode) return
|
||||||
this.highlightBoxNode.remove()
|
this.highlightBoxNode.remove()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 是否存在富文本插件
|
||||||
|
hasRichTextPlugin() {
|
||||||
|
return !!this.mindMap.richText
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Render
|
export default Render
|
||||||
|
|||||||
@ -257,20 +257,18 @@ class Search {
|
|||||||
replaceText = String(replaceText)
|
replaceText = String(replaceText)
|
||||||
// 如果当前搜索文本是替换文本的子串,那么该节点还是符合搜索结果的
|
// 如果当前搜索文本是替换文本的子串,那么该节点还是符合搜索结果的
|
||||||
const keep = replaceText.includes(this.searchText)
|
const keep = replaceText.includes(this.searchText)
|
||||||
|
const hasRichTextPlugin = this.mindMap.renderer.hasRichTextPlugin()
|
||||||
this.matchNodeList.forEach(node => {
|
this.matchNodeList.forEach(node => {
|
||||||
const text = this.getReplacedText(node, this.searchText, replaceText)
|
const text = this.getReplacedText(node, this.searchText, replaceText)
|
||||||
if (this.isNodeInstance(node)) {
|
if (this.isNodeInstance(node)) {
|
||||||
this.mindMap.renderer.setNodeDataRender(
|
const data = {
|
||||||
node,
|
text
|
||||||
{
|
}
|
||||||
text,
|
if (hasRichTextPlugin) data.resetRichText = !!node.getData('richText')
|
||||||
resetRichText: !!node.getData('richText')
|
this.mindMap.renderer.setNodeDataRender(node, data, true)
|
||||||
},
|
|
||||||
true
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
node.data.text = text
|
node.data.text = text
|
||||||
node.data.resetRichText = !!node.data.richText
|
if (hasRichTextPlugin) node.data.resetRichText = !!node.data.richText
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
this.mindMap.render()
|
this.mindMap.render()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user