Skip to content

Commit 6da2a83

Browse files
committed
fix(extension): 修复渐进连线组件启用后,拖拽连线到某个锚点放开后会创建两条连线问题 fix #2140
1 parent 58acc30 commit 6da2a83

File tree

1 file changed

+30
-2
lines changed
  • packages/extension/src/tools/proximity-connect

1 file changed

+30
-2
lines changed

packages/extension/src/tools/proximity-connect/index.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,37 @@ export class ProximityConnect {
7878
},
7979
)
8080
// 节点、锚点拖拽结束事件
81-
this.lf.graphModel.eventCenter.on('node:drop,anchor:dragend', () => {
81+
this.lf.graphModel.eventCenter.on('node:drop', () => {
8282
if (!this.enable) return
8383
this.handleDrop()
8484
})
85+
// 锚点拖拽需要单独判断一下当前拖拽终点是否在某个锚点上,如果是,就不触发插件的连线,以免出现创建了两条连线的问题,表现见 issue 2140
86+
this.lf.graphModel.eventCenter.on('anchor:dragend', ({ e, edgeModel }) => {
87+
if (!this.enable) return
88+
const {
89+
canvasOverlayPosition: { x: eventX, y: eventY },
90+
} = this.lf.graphModel.getPointByClient({
91+
x: e.clientX,
92+
y: e.clientY,
93+
})
94+
95+
if (edgeModel && this.virtualEdge) {
96+
const { id: virtualEdgeId } = this.virtualEdge as BaseEdgeModel
97+
const { targetNodeId } = edgeModel as BaseEdgeModel
98+
const targetNodeModel =
99+
this.lf.graphModel.getNodeModelById(targetNodeId)
100+
const dropPointIsAnchor = targetNodeModel?.anchors.some((anchor) => {
101+
const { x, y } = anchor
102+
return Math.abs(eventX - x) <= 10 && Math.abs(eventY - y) <= 10
103+
})
104+
if (dropPointIsAnchor) {
105+
this.lf.deleteEdge(virtualEdgeId)
106+
return
107+
}
108+
}
109+
110+
this.handleDrop()
111+
})
85112
}
86113

87114
// 节点拖拽动作
@@ -335,6 +362,7 @@ export class ProximityConnect {
335362

336363
// 增加实体边
337364
addActualEdge() {
365+
console.log('addActualEdge')
338366
if (isNil(this.virtualEdge)) return
339367
const {
340368
type,
@@ -346,6 +374,7 @@ export class ProximityConnect {
346374
endPoint,
347375
pointsList,
348376
} = this.virtualEdge
377+
this.lf.deleteEdge(this.virtualEdge.id)
349378
this.lf.addEdge({
350379
type,
351380
sourceNodeId,
@@ -356,7 +385,6 @@ export class ProximityConnect {
356385
endPoint,
357386
pointsList,
358387
})
359-
this.lf.deleteEdge(this.virtualEdge.id)
360388
}
361389

362390
// 设置虚拟边样式

0 commit comments

Comments
 (0)