Fix:修复复制多个节点然后连续粘贴会导致布局混乱的问题
This commit is contained in:
parent
f10f8e0610
commit
656cfa50c6
@ -748,10 +748,12 @@ class Render {
|
|||||||
// 动态指定的子节点数据也需要添加相关属性
|
// 动态指定的子节点数据也需要添加相关属性
|
||||||
appointChildren = addDataToAppointNodes(appointChildren, params)
|
appointChildren = addDataToAppointNodes(appointChildren, params)
|
||||||
const alreadyIsRichText = appointData && appointData.richText
|
const alreadyIsRichText = appointData && appointData.richText
|
||||||
|
let createNewId = false
|
||||||
list.forEach(node => {
|
list.forEach(node => {
|
||||||
if (node.isGeneralization || node.isRoot) {
|
if (node.isGeneralization || node.isRoot) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
appointChildren = simpleDeepClone(appointChildren)
|
||||||
const parent = node.parent
|
const parent = node.parent
|
||||||
const isOneLayer = node.layerIndex === 1
|
const isOneLayer = node.layerIndex === 1
|
||||||
// 新插入节点的默认文本
|
// 新插入节点的默认文本
|
||||||
@ -772,8 +774,9 @@ class Render {
|
|||||||
uid: createUid(),
|
uid: createUid(),
|
||||||
...(appointData || {})
|
...(appointData || {})
|
||||||
},
|
},
|
||||||
children: [...createUidForAppointNodes(appointChildren)]
|
children: [...createUidForAppointNodes(appointChildren, createNewId)]
|
||||||
}
|
}
|
||||||
|
createNewId = true
|
||||||
parent.nodeData.children.splice(index + 1, 0, newNodeData)
|
parent.nodeData.children.splice(index + 1, 0, newNodeData)
|
||||||
})
|
})
|
||||||
// 如果同时对多个节点插入子节点,需要清除原来激活的节点
|
// 如果同时对多个节点插入子节点,需要清除原来激活的节点
|
||||||
@ -801,14 +804,17 @@ class Render {
|
|||||||
}
|
}
|
||||||
if (isRichText) params.resetRichText = true
|
if (isRichText) params.resetRichText = true
|
||||||
nodeList = addDataToAppointNodes(nodeList, params)
|
nodeList = addDataToAppointNodes(nodeList, params)
|
||||||
|
let createNewId = false
|
||||||
list.forEach(node => {
|
list.forEach(node => {
|
||||||
if (node.isGeneralization || node.isRoot) {
|
if (node.isGeneralization || node.isRoot) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
nodeList = simpleDeepClone(nodeList)
|
||||||
const parent = node.parent
|
const parent = node.parent
|
||||||
// 计算插入位置
|
// 计算插入位置
|
||||||
const index = getNodeDataIndex(node)
|
const index = getNodeDataIndex(node)
|
||||||
const newNodeList = createUidForAppointNodes(simpleDeepClone(nodeList))
|
const newNodeList = createUidForAppointNodes(nodeList, createNewId)
|
||||||
|
createNewId = true
|
||||||
parent.nodeData.children.splice(index + 1, 0, ...newNodeList)
|
parent.nodeData.children.splice(index + 1, 0, ...newNodeList)
|
||||||
})
|
})
|
||||||
if (focusNewNode) {
|
if (focusNewNode) {
|
||||||
@ -849,10 +855,12 @@ class Render {
|
|||||||
// 动态指定的子节点数据也需要添加相关属性
|
// 动态指定的子节点数据也需要添加相关属性
|
||||||
appointChildren = addDataToAppointNodes(appointChildren, params)
|
appointChildren = addDataToAppointNodes(appointChildren, params)
|
||||||
const alreadyIsRichText = appointData && appointData.richText
|
const alreadyIsRichText = appointData && appointData.richText
|
||||||
|
let createNewId = false
|
||||||
list.forEach(node => {
|
list.forEach(node => {
|
||||||
if (node.isGeneralization) {
|
if (node.isGeneralization) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
appointChildren = simpleDeepClone(appointChildren)
|
||||||
if (!node.nodeData.children) {
|
if (!node.nodeData.children) {
|
||||||
node.nodeData.children = []
|
node.nodeData.children = []
|
||||||
}
|
}
|
||||||
@ -871,8 +879,9 @@ class Render {
|
|||||||
...params,
|
...params,
|
||||||
...(appointData || {})
|
...(appointData || {})
|
||||||
},
|
},
|
||||||
children: [...createUidForAppointNodes(appointChildren)]
|
children: [...createUidForAppointNodes(appointChildren, createNewId)]
|
||||||
}
|
}
|
||||||
|
createNewId = true
|
||||||
node.nodeData.children.push(newNode)
|
node.nodeData.children.push(newNode)
|
||||||
// 插入子节点时自动展开子节点
|
// 插入子节点时自动展开子节点
|
||||||
node.setData({
|
node.setData({
|
||||||
@ -904,14 +913,18 @@ class Render {
|
|||||||
}
|
}
|
||||||
if (isRichText) params.resetRichText = true
|
if (isRichText) params.resetRichText = true
|
||||||
childList = addDataToAppointNodes(childList, params)
|
childList = addDataToAppointNodes(childList, params)
|
||||||
|
let createNewId = false
|
||||||
list.forEach(node => {
|
list.forEach(node => {
|
||||||
if (node.isGeneralization) {
|
if (node.isGeneralization) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
childList = simpleDeepClone(childList)
|
||||||
if (!node.nodeData.children) {
|
if (!node.nodeData.children) {
|
||||||
node.nodeData.children = []
|
node.nodeData.children = []
|
||||||
}
|
}
|
||||||
childList = createUidForAppointNodes(childList)
|
childList = createUidForAppointNodes(childList, createNewId)
|
||||||
|
// 第一个引用不需要重新创建uid,后面的需要重新创建,否则id会重复
|
||||||
|
createNewId = true
|
||||||
node.nodeData.children.push(...childList)
|
node.nodeData.children.push(...childList)
|
||||||
// 插入子节点时自动展开子节点
|
// 插入子节点时自动展开子节点
|
||||||
node.setData({
|
node.setData({
|
||||||
@ -1526,7 +1539,6 @@ class Render {
|
|||||||
|
|
||||||
// 粘贴节点到节点
|
// 粘贴节点到节点
|
||||||
pasteNode(data) {
|
pasteNode(data) {
|
||||||
data = simpleDeepClone(data)
|
|
||||||
data = formatDataToArray(data)
|
data = formatDataToArray(data)
|
||||||
this.mindMap.execCommand('INSERT_MULTI_CHILD_NODE', [], data)
|
this.mindMap.execCommand('INSERT_MULTI_CHILD_NODE', [], data)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1006,7 +1006,6 @@ export const createUidForAppointNodes = (
|
|||||||
createNewId = false,
|
createNewId = false,
|
||||||
handle = null
|
handle = null
|
||||||
) => {
|
) => {
|
||||||
console.log(appointNodes)
|
|
||||||
const walk = list => {
|
const walk = list => {
|
||||||
list.forEach(node => {
|
list.forEach(node => {
|
||||||
if (!node.data) {
|
if (!node.data) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user