From c87af1708d327231319bbfbceca5add78b44e0ca Mon Sep 17 00:00:00 2001
From: David Sehnal <david.sehnal@gmail.com>
Date: Sat, 2 Mar 2019 16:18:18 +0100
Subject: [PATCH] mol-plugin: structure selection fix

---
 src/mol-plugin/util/structure-element-selection.ts | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/mol-plugin/util/structure-element-selection.ts b/src/mol-plugin/util/structure-element-selection.ts
index 8ebe9d12d..a070ec298 100644
--- a/src/mol-plugin/util/structure-element-selection.ts
+++ b/src/mol-plugin/util/structure-element-selection.ts
@@ -77,12 +77,17 @@ class StructureElementSelectionManager {
         }
         if (!e) return;
 
-        const predIdx = OrderedSet.findPredecessorIndex(e.indices, OrderedSet.min(xs.indices));
+        let predIdx = OrderedSet.findPredecessorIndex(e.indices, OrderedSet.min(xs.indices));
         if (predIdx === 0) return;
 
-        const fst = predIdx < OrderedSet.size(e.indices)
-            ? OrderedSet.getAt(e.indices, predIdx)
-            : OrderedSet.getAt(e.indices, predIdx - 1) + 1 as StructureElement.UnitIndex;
+        let fst;
+
+        if (predIdx < OrderedSet.size(e.indices)) {
+            fst = OrderedSet.getAt(e.indices, predIdx)
+            if (fst > OrderedSet.min(xs.indices)) fst = OrderedSet.getAt(e.indices, predIdx - 1) + 1 as StructureElement.UnitIndex;
+        } else {
+            fst = OrderedSet.getAt(e.indices, predIdx - 1) + 1 as StructureElement.UnitIndex;
+        }
 
         return StructureElement.Loci(entry.selection.structure, [{
             unit: e.unit,
-- 
GitLab