Browse Source

avoid unneccesary marking

Alexander Rose 4 years ago
parent
commit
c9717c2332

+ 13 - 9
src/mol-plugin-state/manager/interactivity.ts

@@ -100,7 +100,9 @@ namespace InteractivityManager {
         }
 
         protected mark(current: Representation.Loci, action: MarkerAction) {
-            for (let p of this.providers) p(current, action);
+            if (!Loci.isEmpty(current.loci)) {
+                for (let p of this.providers) p(current, action);
+            }
         }
 
         constructor(public readonly ctx: PluginContext, props: Partial<Props> = {}) {
@@ -232,14 +234,16 @@ namespace InteractivityManager {
 
         protected mark(current: Representation.Loci, action: MarkerAction.Select | MarkerAction.Deselect) {
             const { loci } = current;
-            if (StructureElement.Loci.is(loci)) {
-                // do a full deselect/select for the current structure so visuals that are
-                // marked with granularity unequal to 'element' and join/intersect operations
-                // are handled properly
-                super.mark({ loci: Structure.Loci(loci.structure) }, MarkerAction.Deselect);
-                super.mark({ loci: this.sel.getLoci(loci.structure) }, MarkerAction.Select);
-            } else {
-                super.mark(current, action);
+            if (!Loci.isEmpty(loci)) {
+                if (StructureElement.Loci.is(loci)) {
+                    // do a full deselect/select for the current structure so visuals that are
+                    // marked with granularity unequal to 'element' and join/intersect operations
+                    // are handled properly
+                    super.mark({ loci: Structure.Loci(loci.structure) }, MarkerAction.Deselect);
+                    super.mark({ loci: this.sel.getLoci(loci.structure) }, MarkerAction.Select);
+                } else {
+                    super.mark(current, action);
+                }
             }
         }
 

+ 4 - 1
src/mol-plugin/behavior/dynamic/representation.ts

@@ -150,9 +150,12 @@ export const SelectLoci = PluginBehavior.create({
             this.subscribeObservable(this.ctx.state.events.object.created, ({ ref }) => this.applySelectMark(ref));
 
             // re-apply select-mark to all representation of an updated structure
-            this.subscribeObservable(this.ctx.state.events.object.updated, ({ ref }) => {
+            this.subscribeObservable(this.ctx.state.events.object.updated, ({ ref, obj, oldObj, action }) => {
                 const cell = this.ctx.state.data.cells.get(ref);
                 if (cell && SO.Molecule.Structure.is(cell.obj)) {
+                    // TODO how to ensure that in-place updates result in compatible structures?
+                    if (obj.data.hashCode === oldObj?.data.hashCode || action === 'in-place') return;
+
                     const reprs = this.ctx.state.data.select(StateSelection.Generators.ofType(SO.Molecule.Structure.Representation3D, ref));
                     for (const repr of reprs) this.applySelectMark(repr.transform.ref, true);
                 }