-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#2471 – fix the issue with select and paste tools with collapsed SGroup
- Loading branch information
1 parent
0822365
commit 9846895
Showing
3 changed files
with
52 additions
and
2 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
packages/ketcher-react/src/script/editor/tool/helper/filterNotInCollapsedSGroup.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Struct, FunctionalGroup } from 'ketcher-core' | ||
|
||
/** | ||
* return only such elements ids that not part of collapsed group | ||
* Addition: if an atom in the collapsed SGroup, but is an AttachmentPoint it will be returned as well. | ||
*/ | ||
export function filterNotInCollapsedSGroup( | ||
itemsToFilter: { atoms?: number[]; bonds?: number[] }, | ||
struct: Struct | ||
) { | ||
return { | ||
atoms: | ||
itemsToFilter.atoms?.filter((atomId) => { | ||
const groupId = struct.getGroupIdFromAtomId(atomId) | ||
if (isNotCollapsedSGroup(groupId, struct)) { | ||
return true | ||
} else { | ||
return FunctionalGroup.isAttachmentPointAtom(atomId, struct) | ||
} | ||
}) ?? [], | ||
bonds: | ||
itemsToFilter.bonds?.filter((bondId) => { | ||
const groupId = struct.getGroupIdFromBondId(bondId) | ||
return isNotCollapsedSGroup(groupId, struct) | ||
}) ?? [] | ||
} | ||
} | ||
|
||
function isNotCollapsedSGroup(groupId: number | null, struct: Struct): boolean { | ||
if (groupId === null) { | ||
return true | ||
} | ||
const sGroup = struct.sgroups.get(groupId) | ||
if (!sGroup) { | ||
throw new Error( | ||
`sGroup with id = "${groupId}" must be defined, unexpected behaviour` | ||
) | ||
} | ||
return sGroup.checkAttr('expanded', true) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters