Skip to content

Commit

Permalink
#117 cut command does not work for Simple Objects (#122)
Browse files Browse the repository at this point in the history
- Add SimpleObjects to Struct.clone()
  • Loading branch information
Vesdet committed Nov 27, 2020
1 parent a4c8397 commit 1b6d05c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
21 changes: 18 additions & 3 deletions src/script/chem/struct/index.js
Expand Up @@ -70,16 +70,24 @@ Struct.prototype.isBlank = function () {
* @param bondSet { Pile<number>? }
* @param dropRxnSymbols { boolean? }
* @param aidMap { Map<number, number>? }
* @param simpleObjectsSet { Pile<number>? }
* @returns { Struct }
*/
Struct.prototype.clone = function (atomSet, bondSet, dropRxnSymbols, aidMap) {
Struct.prototype.clone = function (
atomSet,
bondSet,
dropRxnSymbols,
aidMap,
simpleObjectsSet
) {
return this.mergeInto(
new Struct(),
atomSet,
bondSet,
dropRxnSymbols,
false,
aidMap
aidMap,
simpleObjectsSet
)
}

Expand Down Expand Up @@ -121,6 +129,7 @@ Struct.prototype.getFragment = function (fid) {
* @param dropRxnSymbols { boolean? }
* @param keepAllRGroups { boolean? }
* @param aidMap { Map<number, number>? }
* @param simpleObjectsSet { Pile<number>? }
* @returns { Struct }
*/
Struct.prototype.mergeInto = function (
Expand All @@ -129,11 +138,13 @@ Struct.prototype.mergeInto = function (
bondSet,
dropRxnSymbols,
keepAllRGroups,
aidMap
aidMap,
simpleObjectsSet
) {
// eslint-disable-line max-params, max-statements
atomSet = atomSet || new Pile(this.atoms.keys())
bondSet = bondSet || new Pile(this.bonds.keys())
simpleObjectsSet = simpleObjectsSet || new Pile(this.simpleObjects.keys())
aidMap = aidMap || new Map()

bondSet = bondSet.filter(bid => {
Expand Down Expand Up @@ -213,6 +224,10 @@ Struct.prototype.mergeInto = function (
else cp.sGroupForest.insert(sg)
})

simpleObjectsSet.forEach(soid => {
cp.simpleObjects.add(this.simpleObjects.get(soid).clone())
})

if (!dropRxnSymbols) {
cp.isReaction = this.isReaction
this.rxnArrows.forEach(item => {
Expand Down
4 changes: 3 additions & 1 deletion src/script/editor/index.js
Expand Up @@ -374,7 +374,9 @@ Editor.prototype.structSelected = function () {
const dst = struct.clone(
new Pile(selection.atoms),
new Pile(selection.bonds),
true
true,
null,
new Pile(selection.simpleObjects)
)

// Copy by its own as Struct.clone doesn't support
Expand Down

0 comments on commit 1b6d05c

Please sign in to comment.