Skip to content

Commit

Permalink
#2213 - added hight priority for sgroup data
Browse files Browse the repository at this point in the history
  • Loading branch information
VandaEPAM committed Apr 27, 2023
1 parent a6960cc commit c8c751b
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions packages/ketcher-react/src/script/editor/shared/closest.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,22 +454,29 @@ function findClosestItem(restruct, pos, maps, skip, scale) {
// eslint-disable-line max-params
maps = maps || Object.keys(findMaps)

return maps.reduce((res, mp) => {
let priorityItem = null

const closestItem = maps.reduce((res, mp) => {
const minDist = res ? res.dist : null
const item = findMaps[mp](restruct, pos, skip, minDist, scale)

if (item !== null && (res === null || item.dist < res.dist)) {
const { id, dist, ...other } = item
return {
if (item !== null) {
const enrichedItem = {
map: mp,
id: id,
dist: dist,
...other
...item
}

if (mp === 'sgroupData') {
priorityItem = enrichedItem
} else if (res === null || item.dist < res.dist) {
return enrichedItem
}
}

return res
}, null)

return priorityItem || closestItem
}

/**
Expand Down

0 comments on commit c8c751b

Please sign in to comment.