From b40df2f1e3a00ee4e54ffc84aec4976bcec3030a Mon Sep 17 00:00:00 2001 From: Alexander Rose <alex.rose@rcsb.org> Date: Fri, 21 Jun 2019 16:55:12 -0700 Subject: [PATCH] sequence, on state tree change improvments --- src/mol-model/structure/structure/structure.ts | 5 +++++ src/mol-plugin/ui/sequence.tsx | 4 +++- src/mol-state/tree/spine.ts | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/mol-model/structure/structure/structure.ts b/src/mol-model/structure/structure/structure.ts index 03569e40a..724bec9bc 100644 --- a/src/mol-model/structure/structure/structure.ts +++ b/src/mol-model/structure/structure/structure.ts @@ -513,6 +513,11 @@ namespace Structure { return areEquivalent(a.parent || a, b.parent || b) } + /** Check if the structures or their parents are equal */ + export function areParentsEqual(a: Structure, b: Structure) { + return (a.parent || a) === (b.parent || b) + } + export class ElementLocationIterator implements Iterator<StructureElement> { private current = StructureElement.create(); private unitIndex = 0; diff --git a/src/mol-plugin/ui/sequence.tsx b/src/mol-plugin/ui/sequence.tsx index b8f9569f5..caab759f3 100644 --- a/src/mol-plugin/ui/sequence.tsx +++ b/src/mol-plugin/ui/sequence.tsx @@ -128,7 +128,9 @@ export class SequenceView extends PluginUIComponent<{ }, SequenceViewState> { this.subscribe(this.plugin.state.behavior.currentObject, o => { const current = this.plugin.state.dataState.cells.get(o.ref)!; this.spine.current = current - this.setState(this.getInitialState()) + if (!Structure.areParentsEqual(this.state.structure, this.getStructure())) { + this.setState(this.getInitialState()) + } }); this.subscribe(this.plugin.events.state.object.updated, ({ ref, state }) => { diff --git a/src/mol-state/tree/spine.ts b/src/mol-state/tree/spine.ts index 9adc01e7c..667c8a028 100644 --- a/src/mol-state/tree/spine.ts +++ b/src/mol-state/tree/spine.ts @@ -36,15 +36,15 @@ namespace StateTreeSpine { getRootOfType<T extends StateObject.Ctor>(t: T): StateObject.From<T> | undefined { if (!this._current) return void 0; - let cell = this._current; + let cell = this._current; // check current first let ret: StateObjectCell | undefined = void 0; while (true) { - cell = this.cells.get(cell.transform.parent)!; if (!cell.obj) return void 0; if (cell.obj.type === t.type) { ret = cell; } if (cell.transform.ref === StateTransform.RootRef) return ret ? ret.obj as StateObject.From<T> : void 0; + cell = this.cells.get(cell.transform.parent)!; // assign parent for next check } } -- GitLab