diff --git a/src/Add-on/DrawBoard/ActivityLayerBoardTool.ts b/src/Add-on/DrawBoard/ActivityLayerBoardTool.ts index e2594ed26..fe6c32f08 100644 --- a/src/Add-on/DrawBoard/ActivityLayerBoardTool.ts +++ b/src/Add-on/DrawBoard/ActivityLayerBoardTool.ts @@ -278,12 +278,13 @@ class ActivityLayerBoardTool private AppendBoard(br: Board, brNailMap: WeakMap, nails: CylinderHole[]) { let oldNailIds = br.LayerNails.filter(n => n?.Object); + this.HandleNailList(nails, oldNailIds, brNailMap); for (let i = nails.length; i < oldNailIds.length; i++) oldNailIds[i]?.Object?.Erase(); - for (let i = 0; i < nails.length; i++) { let nId: ObjectId; + let otherBoard = brNailMap.get(nails[i]); if (i < oldNailIds.length) { let nail = oldNailIds[i].Object as CylinderHole; @@ -301,13 +302,55 @@ class ActivityLayerBoardTool br.Db.ModelSpace.Append(nails[i]); nId = nails[i].Id; br.AppendNails([nId]); - let otherBoard = brNailMap.get(nails[i]); nails[i].MId = br.Id; nails[i].FId = otherBoard.Id; otherBoard.AppendNails([nId]); } } } + private HandleNailList(newNails: CylinderHole[], oldNails: ObjectId[], naiMap: WeakMap) + { + if (oldNails.length < newNails.length) + { + let temp: CylinderHole[] = []; + for (let i = 0; i < oldNails.length; i++) + { + let nail = oldNails[i].Object as CylinderHole; + if (newNails.length === 0) break; + let j = 0; + for (; j < newNails.length; j++) + { + let newNail = newNails[j] as CylinderHole; + let otherBoard = naiMap.get(newNail); + if (otherBoard.Id === nail.FId) + break; + } + if (j < newNails.length) + temp.push(...newNails.splice(j, 1)); + } + newNails.unshift(...temp); + } + else + { + let temp: ObjectId[] = []; + + for (let i = 0; i < newNails.length; i++) + { + let nail = newNails[i]; + let otherBoard = naiMap.get(nail); + let j = 0; + for (; j < oldNails.length; j++) + { + let oldNail = oldNails[j].Object as CylinderHole; + if (oldNail.FId === otherBoard.Id) + break; + } + if (j < oldNails.length) + temp.push(...oldNails.splice(j, 1)); + } + oldNails.unshift(...temp); + } + } } export const activityLayerBoardTool = new ActivityLayerBoardTool();