fix: deregister tags component when needed

This commit is contained in:
Baptiste Grob
2020-09-07 18:02:40 +02:00
parent 6717907dd3
commit 2055c6d55d

View File

@@ -209,6 +209,12 @@ class EditorViewCtrl extends PureViewCtrl<{}, EditorState> {
}); });
} }
$onDestroy() {
if (this.state.tagsComponent) {
this.application.componentManager!.deregisterComponent(this.state.tagsComponent.uuid);
}
}
/** @override */ /** @override */
getInitialState() { getInitialState() {
return { return {
@@ -1058,10 +1064,17 @@ class EditorViewCtrl extends PureViewCtrl<{}, EditorState> {
const [tagsComponent] = const [tagsComponent] =
this.application.componentManager!.componentsForArea(ComponentArea.NoteTags); this.application.componentManager!.componentsForArea(ComponentArea.NoteTags);
if (tagsComponent?.uuid !== this.state.tagsComponent?.uuid) { if (tagsComponent?.uuid !== this.state.tagsComponent?.uuid) {
this.setState({ if (tagsComponent) {
tagsComponent: tagsComponent?.active ? tagsComponent : undefined if (tagsComponent.active) {
}); this.application.componentManager!.registerComponent(tagsComponent.uuid);
} else {
this.application.componentManager!.deregisterComponent(tagsComponent.uuid);
}
}
} }
this.setState({
tagsComponent: tagsComponent?.active ? tagsComponent : undefined
});
this.application.componentManager!.contextItemDidChangeInArea(ComponentArea.NoteTags); this.application.componentManager!.contextItemDidChangeInArea(ComponentArea.NoteTags);
} }