Skip to content

Commit

Permalink
fix: 馃悰 find snap view
Browse files Browse the repository at this point in the history
  • Loading branch information
bubkoo committed Sep 22, 2020
1 parent 6c8b63c commit 6f5fab2
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions packages/x6/src/view/edge.ts
Expand Up @@ -2230,20 +2230,21 @@ export class EdgeView<
}
}

view.$('[magnet]').each((index, elem) => {
const magnet = elem as Element
const bbox = view.getBBoxOfElement(magnet)
distance = pos.distance(bbox.getCenter())
if (distance < radius && distance < minDistance) {
if (
prevMagnet === magnet ||
graph.hook.validateConnection(
...data.getValidateConnectionArgs(view, magnet),
)
) {
minDistance = distance
data.closestView = view
data.closestMagnet = magnet
view.container.querySelectorAll('[magnet]').forEach((magnet) => {
if (magnet.getAttribute('magnet') !== 'false') {
const bbox = view.getBBoxOfElement(magnet)
distance = pos.distance(bbox.getCenter())
if (distance < radius && distance < minDistance) {
if (
prevMagnet === magnet ||
graph.hook.validateConnection(
...data.getValidateConnectionArgs(view, magnet),
)
) {
minDistance = distance
data.closestView = view
data.closestMagnet = magnet
}
}
}
})
Expand Down

0 comments on commit 6f5fab2

Please sign in to comment.