From 58a49a8512362f2c16a86374f6849275b0099b67 Mon Sep 17 00:00:00 2001
From: Alexander Rose <alexander.rose@weirdbyte.de>
Date: Sat, 22 Jun 2019 08:12:07 -0700
Subject: [PATCH] fix handling of structure loci selection

---
 src/mol-model/structure/structure/structure.ts | 10 +++++++++-
 src/mol-plugin/util/interactivity.ts           |  3 +++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/mol-model/structure/structure/structure.ts b/src/mol-model/structure/structure/structure.ts
index 724bec9bc..d91b02346 100644
--- a/src/mol-model/structure/structure/structure.ts
+++ b/src/mol-model/structure/structure/structure.ts
@@ -5,7 +5,7 @@
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
 
-import { IntMap, SortedArray, Iterator, Segmentation } from '../../../mol-data/int'
+import { IntMap, SortedArray, Iterator, Segmentation, Interval } from '../../../mol-data/int'
 import { UniqueArray } from '../../../mol-data/generic'
 import { SymmetryOperator } from '../../../mol-math/geometry/symmetry-operator'
 import { Model, ElementIndex } from '../model'
@@ -345,6 +345,14 @@ namespace Structure {
         return { kind: 'structure-loci', structure };
     }
 
+    export function toStructureElementLoci(loci: Loci): StructureElement.Loci {
+        const elements: StructureElement.Loci['elements'][0][] = []
+        for (const unit of loci.structure.units) {
+            elements.push({ unit, indices: Interval.ofBounds(0, unit.elements.length) })
+        }
+        return StructureElement.Loci(loci.structure, elements);
+    }
+
     export function isLoci(x: any): x is Loci {
         return !!x && x.kind === 'structure-loci';
     }
diff --git a/src/mol-plugin/util/interactivity.ts b/src/mol-plugin/util/interactivity.ts
index 61fff02d1..dac8ca4bc 100644
--- a/src/mol-plugin/util/interactivity.ts
+++ b/src/mol-plugin/util/interactivity.ts
@@ -97,6 +97,9 @@ namespace Interactivity {
                 loci = Link.toStructureElementLoci(loci)
             }
             loci = Granularity[this.props.granularity](loci)
+            if (Structure.isLoci(loci)) {
+                loci = Structure.toStructureElementLoci(loci)
+            }
             if (StructureElement.isLoci(loci) && loci.structure.parent) {
                 loci = StructureElement.Loci.remap(loci, loci.structure.parent)
             }
-- 
GitLab