From abe506182e302a7ec43248d7fda81345f55f7b59 Mon Sep 17 00:00:00 2001
From: Alexander Rose <alexander.rose@weirdbyte.de>
Date: Sat, 29 Jan 2022 11:21:48 -0800
Subject: [PATCH] fix multi-instance entity label display

- fix empty elements created in extendToAllInstances
---
 CHANGELOG.md                                      |  2 ++
 src/mol-model/structure/structure/element/loci.ts |  6 ++++--
 src/mol-plugin/behavior/dynamic/representation.ts | 15 +++++++++------
 3 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 28d051aa7..2c81e8913 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,8 @@ Note that since we don't clearly distinguish between a public and private interf
 ## [Unreleased]
 
 - Fix color smoothing of elongated structures (by fixing ``Sphere.expand`` for spheres with highly directional extrema)
+- Fix entity label not displayed when multiple instances of the same entity are highlighted
+- Fix empty elements created in ``StructureElement.Loci.extendToAllInstances``
 
 ## [v3.0.1] - 2022-01-27
 
diff --git a/src/mol-model/structure/structure/element/loci.ts b/src/mol-model/structure/structure/element/loci.ts
index 53c2780c6..e920a0929 100644
--- a/src/mol-model/structure/structure/element/loci.ts
+++ b/src/mol-model/structure/structure/element/loci.ts
@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2017-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2017-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author David Sehnal <david.sehnal@gmail.com>
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
@@ -497,7 +497,9 @@ export namespace Loci {
             if (!elementIndices) continue;
 
             const indices = getUnitIndices(unit.elements, elementIndices);
-            elements[elements.length] = { unit, indices };
+            if (OrderedSet.size(indices)) {
+                elements[elements.length] = { unit, indices };
+            }
         }
 
         return Loci(loci.structure, elements);
diff --git a/src/mol-plugin/behavior/dynamic/representation.ts b/src/mol-plugin/behavior/dynamic/representation.ts
index 2ab509a86..11fe074c1 100644
--- a/src/mol-plugin/behavior/dynamic/representation.ts
+++ b/src/mol-plugin/behavior/dynamic/representation.ts
@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2018-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author David Sehnal <david.sehnal@gmail.com>
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
@@ -212,11 +212,14 @@ export const DefaultLociLabelProvider = PluginBehavior.create({
         private f = {
             label: (loci: Loci) => {
                 const label: string[] = [];
-                if (StructureElement.Loci.is(loci) && loci.elements.length === 1) {
-                    const { unit: u } = loci.elements[0];
-                    const l = StructureElement.Location.create(loci.structure, u, u.elements[0]);
-                    const name = StructureProperties.entity.pdbx_description(l).join(', ');
-                    label.push(name);
+                if (StructureElement.Loci.is(loci)) {
+                    const entityNames = new Set<string>();
+                    for (const { unit: u } of loci.elements) {
+                        const l = StructureElement.Location.create(loci.structure, u, u.elements[0]);
+                        const name = StructureProperties.entity.pdbx_description(l).join(', ');
+                        entityNames.add(name);
+                    }
+                    if (entityNames.size === 1) entityNames.forEach(name => label.push(name));
                 }
                 label.push(lociLabel(loci));
                 return label.filter(l => !!l).join('</br>');
-- 
GitLab