fix: prevent infinite loop while switching between notes with editors
This commit is contained in:
@@ -344,21 +344,25 @@ class EditorViewCtrl extends PureViewCtrl<{}, EditorState> {
|
|||||||
const newEditor = this.application.componentManager!.editorForNote(this.note);
|
const newEditor = this.application.componentManager!.editorForNote(this.note);
|
||||||
const currentEditor = this.state.editorComponent;
|
const currentEditor = this.state.editorComponent;
|
||||||
if (currentEditor?.uuid !== newEditor?.uuid) {
|
if (currentEditor?.uuid !== newEditor?.uuid) {
|
||||||
await this.setState({
|
const unloading = this.setState({
|
||||||
editorComponent: newEditor,
|
|
||||||
/** Unload current component view so that we create a new one */
|
/** Unload current component view so that we create a new one */
|
||||||
editorUnloading: true
|
editorUnloading: true
|
||||||
});
|
});
|
||||||
if (newEditor && !newEditor.active) {
|
if (newEditor && !newEditor.active) {
|
||||||
|
/** Activate the new editor while the component view is unloading */
|
||||||
await this.application.componentManager!.activateComponent(newEditor.uuid);
|
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.application.componentManager!.deactivateComponent(currentEditor.uuid);
|
||||||
}
|
}
|
||||||
await this.setState({
|
await reloading;
|
||||||
/** Reload component view */
|
|
||||||
editorUnloading: false
|
|
||||||
});
|
|
||||||
this.reloadFont();
|
this.reloadFont();
|
||||||
}
|
}
|
||||||
this.application.componentManager!.contextItemDidChangeInArea(ComponentArea.Editor);
|
this.application.componentManager!.contextItemDidChangeInArea(ComponentArea.Editor);
|
||||||
|
|||||||
Reference in New Issue
Block a user