From d436d3d5b40ddba34f886d8e862687e8b0484495 Mon Sep 17 00:00:00 2001
From: Alexander Rose <alexander.rose@weirdbyte.de>
Date: Sat, 2 Jun 2018 17:30:53 -0400
Subject: [PATCH] take objectId into account for hoverSelection, clear
 hoverSelection

---
 src/mol-geo/representation/structure/spacefill.ts |  8 ++++++--
 src/mol-geo/representation/structure/utils.ts     | 14 ++++++++++----
 src/mol-view/viewer.ts                            | 10 +++++-----
 3 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/src/mol-geo/representation/structure/spacefill.ts b/src/mol-geo/representation/structure/spacefill.ts
index 49e15e207..f2ace9de1 100644
--- a/src/mol-geo/representation/structure/spacefill.ts
+++ b/src/mol-geo/representation/structure/spacefill.ts
@@ -14,7 +14,7 @@ import { Unit, Element, Queries } from 'mol-model/structure';
 import { UnitsRepresentation, DefaultStructureProps } from './index';
 import { Task } from 'mol-task'
 import { MeshBuilder } from '../../shape/mesh-builder';
-import { createTransforms, createColors, createFlags } from './utils';
+import { createTransforms, createColors, createFlags, createEmptyFlags } from './utils';
 import VertexMap from '../../shape/vertex-map';
 import { icosahedronVertexCount } from '../../primitive/icosahedron';
 import { deepEqual, defaults } from 'mol-util';
@@ -165,7 +165,11 @@ export default function Spacefill(): UnitsRepresentation<SpacefillProps> {
 
                 if (newProps.hoverSelection !== currentProps.hoverSelection) {
                     await ctx.update('Computing spacefill flags');
-                    createFlags(currentGroup, newProps.hoverSelection.instanceId, newProps.hoverSelection.elementId, spheres.values)
+                    if (newProps.hoverSelection.objectId === spheres.id) {
+                        createFlags(currentGroup, newProps.hoverSelection.instanceId, newProps.hoverSelection.elementId, spheres.values)
+                    } else {
+                        createEmptyFlags(spheres.values)
+                    }
                 }
 
                 ValueCell.updateIfChanged(spheres.values.uAlpha, newProps.alpha)
diff --git a/src/mol-geo/representation/structure/utils.ts b/src/mol-geo/representation/structure/utils.ts
index 594588a2f..cee35dd1e 100644
--- a/src/mol-geo/representation/structure/utils.ts
+++ b/src/mol-geo/representation/structure/utils.ts
@@ -82,9 +82,15 @@ export function createFlags(group: Unit.SymmetryGroup, instanceId: number, eleme
 }
 
 const emptyFlagTexture = { array: new Uint8Array(1), width: 1, height: 1 }
-export function createEmptyFlags() {
-    return {
-        tFlag: ValueCell.create(emptyFlagTexture),
-        uFlagTexSize: ValueCell.create(Vec2.create(1, 1)),
+export function createEmptyFlags(flagData?: FlagData) {
+    if (flagData) {
+        ValueCell.update(flagData.tFlag, emptyFlagTexture)
+        ValueCell.update(flagData.uFlagTexSize, Vec2.create(1, 1))
+        return flagData
+    } else {
+        return {
+            tFlag: ValueCell.create(emptyFlagTexture),
+            uFlagTexSize: ValueCell.create(Vec2.create(1, 1)),
+        }
     }
 }
\ No newline at end of file
diff --git a/src/mol-view/viewer.ts b/src/mol-view/viewer.ts
index 4dd8480a1..3dbda0a42 100644
--- a/src/mol-view/viewer.ts
+++ b/src/mol-view/viewer.ts
@@ -83,12 +83,12 @@ namespace Viewer {
                 const info = repr.getLabel(p)
                 if (info) {
                     label = info.label
-                    // TODO do better, take objectId fully into account
-                    repr.update({ hoverSelection: p }).run().then(() => {
-                        scene.update()
-                        requestDraw()
-                    })
                 }
+                // TODO do better, take objectId fully into account
+                repr.update({ hoverSelection: p }).run().then(() => {
+                    scene.update()
+                    requestDraw()
+                })
             })
             identified.next(`Object: ${p.objectId}, Instance: ${p.instanceId}, Element: ${p.elementId}, Label: ${label}`)
         })
-- 
GitLab