From 2055c6d55dcd1231a71eb370b7721162edf4ffbd Mon Sep 17 00:00:00 2001 From: Baptiste Grob <60621355+baptiste-grob@users.noreply.github.com> Date: Mon, 7 Sep 2020 18:02:40 +0200 Subject: [PATCH] fix: deregister tags component when needed --- .../javascripts/views/editor/editor_view.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/views/editor/editor_view.ts b/app/assets/javascripts/views/editor/editor_view.ts index 5aeae241df2..72a87381f4b 100644 --- a/app/assets/javascripts/views/editor/editor_view.ts +++ b/app/assets/javascripts/views/editor/editor_view.ts @@ -209,6 +209,12 @@ class EditorViewCtrl extends PureViewCtrl<{}, EditorState> { }); } + $onDestroy() { + if (this.state.tagsComponent) { + this.application.componentManager!.deregisterComponent(this.state.tagsComponent.uuid); + } + } + /** @override */ getInitialState() { return { @@ -1058,10 +1064,17 @@ class EditorViewCtrl extends PureViewCtrl<{}, EditorState> { const [tagsComponent] = this.application.componentManager!.componentsForArea(ComponentArea.NoteTags); if (tagsComponent?.uuid !== this.state.tagsComponent?.uuid) { - this.setState({ - tagsComponent: tagsComponent?.active ? tagsComponent : undefined - }); + if (tagsComponent) { + 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); }