diff --git a/packages/base/src/panelview/objectproperties.tsx b/packages/base/src/panelview/objectproperties.tsx index ee58cf58..29d070f6 100644 --- a/packages/base/src/panelview/objectproperties.tsx +++ b/packages/base/src/panelview/objectproperties.tsx @@ -75,22 +75,30 @@ class ObjectPropertiesReact extends React.Component { if (changed) { this.props.cpModel.disconnect(this._sharedJcadModelChanged); this.props.cpModel.disconnect(this._onClientSharedStateChanged); + const currentModel = changed.context.model; + currentModel.sharedObjectsChanged.connect(this._sharedJcadModelChanged); + const clients = currentModel.sharedModel.awareness.getStates() as Map< + number, + IJupyterCadClientState + >; - changed.context.model.sharedObjectsChanged.connect( - this._sharedJcadModelChanged - ); - changed.context.model.clientStateChanged.connect( - this._onClientSharedStateChanged + this.setState( + old => ({ + jcadOption: undefined, + selectedObjectData: undefined, + selectedObject: undefined, + schema: undefined, + filePath: changed.context.localPath, + jcadObject: this.props.cpModel.jcadModel?.getAllObject(), + clientId: currentModel.getClientId() + }), + () => { + this._onClientSharedStateChanged(currentModel, clients); + currentModel.clientStateChanged.connect( + this._onClientSharedStateChanged + ); + } ); - this.setState(old => ({ - jcadOption: undefined, - selectedObjectData: undefined, - selectedObject: undefined, - schema: undefined, - filePath: changed.context.localPath, - jcadObject: this.props.cpModel.jcadModel?.getAllObject(), - clientId: changed.context.model.getClientId() - })); } else { this.setState({ jcadOption: undefined, @@ -251,6 +259,7 @@ class ObjectPropertiesReact extends React.Component { newState = localState; } } + if (newState) { const selection = newState.selected.value; const selectedObjectNames = Object.keys(selection || {}); @@ -294,6 +303,13 @@ class ObjectPropertiesReact extends React.Component { })); } } + } else { + this.setState(old => ({ + ...old, + schema: undefined, + selectedObject: '', + selectedObjectData: undefined + })); } }; diff --git a/packages/base/src/panelview/rightpanel.tsx b/packages/base/src/panelview/rightpanel.tsx index 2848f886..e2670707 100644 --- a/packages/base/src/panelview/rightpanel.tsx +++ b/packages/base/src/panelview/rightpanel.tsx @@ -32,7 +32,6 @@ export class RightPanelWidget extends SidePanel { clients: Map ) => { const localState = sender.localState; - if (!localState) { return; } @@ -49,7 +48,6 @@ export class RightPanelWidget extends SidePanel { } else if (localState.selected?.value) { selection = localState.selected.value; } - const selectionNames = Object.keys(selection); if (selectionNames.length === 1) { const selected = selectionNames[0]; @@ -73,6 +71,11 @@ export class RightPanelWidget extends SidePanel { if (changed.context.model.sharedModel.editable) { currentModel = changed.context.model; + const clients = currentModel.sharedModel.awareness.getStates() as Map< + number, + IJupyterCadClientState + >; + updateTitle(currentModel, clients); currentModel.clientStateChanged.connect(updateTitle); properties.show();