From c8c751be2761158384a98b4ae1402bd81f1312d6 Mon Sep 17 00:00:00 2001 From: Vanda_Ponikarova Date: Thu, 27 Apr 2023 12:10:23 +0400 Subject: [PATCH] #2213 - added hight priority for sgroup data --- .../src/script/editor/shared/closest.js | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/ketcher-react/src/script/editor/shared/closest.js b/packages/ketcher-react/src/script/editor/shared/closest.js index 83842a56ff..c73cbf0484 100644 --- a/packages/ketcher-react/src/script/editor/shared/closest.js +++ b/packages/ketcher-react/src/script/editor/shared/closest.js @@ -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 } /**