Skip to content
Snippets Groups Projects
Commit b40df2f1 authored by Alexander Rose's avatar Alexander Rose
Browse files

sequence, on state tree change improvments

parent 884cb0d9
No related branches found
No related tags found
No related merge requests found
...@@ -513,6 +513,11 @@ namespace Structure { ...@@ -513,6 +513,11 @@ namespace Structure {
return areEquivalent(a.parent || a, b.parent || b) 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> { export class ElementLocationIterator implements Iterator<StructureElement> {
private current = StructureElement.create(); private current = StructureElement.create();
private unitIndex = 0; private unitIndex = 0;
......
...@@ -128,7 +128,9 @@ export class SequenceView extends PluginUIComponent<{ }, SequenceViewState> { ...@@ -128,7 +128,9 @@ export class SequenceView extends PluginUIComponent<{ }, SequenceViewState> {
this.subscribe(this.plugin.state.behavior.currentObject, o => { this.subscribe(this.plugin.state.behavior.currentObject, o => {
const current = this.plugin.state.dataState.cells.get(o.ref)!; const current = this.plugin.state.dataState.cells.get(o.ref)!;
this.spine.current = current 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 }) => { this.subscribe(this.plugin.events.state.object.updated, ({ ref, state }) => {
......
...@@ -36,15 +36,15 @@ namespace StateTreeSpine { ...@@ -36,15 +36,15 @@ namespace StateTreeSpine {
getRootOfType<T extends StateObject.Ctor>(t: T): StateObject.From<T> | undefined { getRootOfType<T extends StateObject.Ctor>(t: T): StateObject.From<T> | undefined {
if (!this._current) return void 0; if (!this._current) return void 0;
let cell = this._current; let cell = this._current; // check current first
let ret: StateObjectCell | undefined = void 0; let ret: StateObjectCell | undefined = void 0;
while (true) { while (true) {
cell = this.cells.get(cell.transform.parent)!;
if (!cell.obj) return void 0; if (!cell.obj) return void 0;
if (cell.obj.type === t.type) { if (cell.obj.type === t.type) {
ret = cell; ret = cell;
} }
if (cell.transform.ref === StateTransform.RootRef) return ret ? ret.obj as StateObject.From<T> : void 0; 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
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment