Browse Source

fix updateFocusRepr (#903)

David Sehnal 1 year ago
parent
commit
4cc2073eaa

+ 2 - 0
CHANGELOG.md

@@ -6,6 +6,8 @@ Note that since we don't clearly distinguish between a public and private interf
 
 ## [Unreleased]
 
+- Do not call `updateFocusRepr` if default `StructureFocusRepresentation` isn't present.
+
 ## [v3.39.0] - 2023-09-02
 
 - Add some elements support for `guessElementSymbolString` function

+ 3 - 1
src/mol-plugin-state/builder/structure/representation-preset.ts

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2019-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2019-2023 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>
@@ -94,6 +94,8 @@ export namespace StructureRepresentationPresetProvider {
     }
 
     export function updateFocusRepr<T extends ColorTheme.BuiltIn>(plugin: PluginContext, structure: Structure, themeName: T | undefined, themeParams: ColorTheme.BuiltInParams<T> | undefined) {
+        if (!plugin.state.hasBehavior(StructureFocusRepresentation)) return;
+
         return plugin.state.updateBehavior(StructureFocusRepresentation, p => {
             const c = createStructureColorThemeParams(plugin, structure, 'ball-and-stick', themeName || 'element-symbol', themeParams);
             p.surroundingsParams.colorTheme = c;

+ 4 - 0
src/mol-plugin/state.ts

@@ -116,6 +116,10 @@ class PluginState extends PluginComponent {
         return PluginCommands.State.Update(this.plugin, { state, tree, options: { canUndo } });
     }
 
+    hasBehavior(behavior: StateTransformer) {
+        return this.behaviors.tree.transforms.has(behavior.id);
+    }
+
     updateBehavior<T extends StateTransformer>(behavior: T, params: (old: StateTransformer.Params<T>) => (void | StateTransformer.Params<T>)) {
         const tree = this.behaviors.build();
         if (!this.behaviors.tree.transforms.has(behavior.id)) {