diff --git a/src/mol-plugin/util/structure-element-selection.ts b/src/mol-plugin/util/structure-element-selection.ts index 8ebe9d12d1bc4c2cda4583f8e62890aa20bf8a72..a070ec298ee2a5b349ffccad5872a90f8abf5c26 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,