From 65468a1a72bff696d9b7bf6f8364a733d36c1070 Mon Sep 17 00:00:00 2001 From: Baptiste Grob <60621355+baptiste-grob@users.noreply.github.com> Date: Thu, 20 Aug 2020 13:11:11 +0200 Subject: [PATCH] fix: prevent infinite loop while switching between notes with editors --- .../javascripts/views/editor/editor_view.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/views/editor/editor_view.ts b/app/assets/javascripts/views/editor/editor_view.ts index 9db95e47d..9318486ce 100644 --- a/app/assets/javascripts/views/editor/editor_view.ts +++ b/app/assets/javascripts/views/editor/editor_view.ts @@ -344,21 +344,25 @@ class EditorViewCtrl extends PureViewCtrl<{}, EditorState> { const newEditor = this.application.componentManager!.editorForNote(this.note); const currentEditor = this.state.editorComponent; if (currentEditor?.uuid !== newEditor?.uuid) { - await this.setState({ - editorComponent: newEditor, + const unloading = this.setState({ /** Unload current component view so that we create a new one */ editorUnloading: true }); if (newEditor && !newEditor.active) { + /** Activate the new editor while the component view is unloading */ await this.application.componentManager!.activateComponent(newEditor.uuid); } - if (currentEditor) { + await unloading; + const reloading = this.setState({ + /** Reload component view */ + editorComponent: newEditor, + editorUnloading: false, + }); + if (currentEditor?.active) { + /** Deactivate the current (previous) editor while the editor view is reloading */ await this.application.componentManager!.deactivateComponent(currentEditor.uuid); } - await this.setState({ - /** Reload component view */ - editorUnloading: false - }); + await reloading; this.reloadFont(); } this.application.componentManager!.contextItemDidChangeInArea(ComponentArea.Editor);