fix: debounce editor reloading to handle fast fire

This commit is contained in:
Mo
2021-12-27 16:29:18 -06:00
parent 3140b17c20
commit 06fae3acda

View File

@@ -21,7 +21,7 @@ import {
ItemMutator,
ProposedSecondsToDeferUILevelSessionExpirationDuringActiveInteraction,
} from '@standardnotes/snjs';
import { isDesktopApplication } from '@/utils';
import { debounce, isDesktopApplication } from '@/utils';
import { KeyboardModifier, KeyboardKey } from '@/services/ioService';
import template from './editor-view.pug';
import { PureViewCtrl } from '@Views/abstract/pure_view_ctrl';
@@ -130,6 +130,10 @@ export class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
this.onEditorLoad = () => {
this.application.getDesktopService().redoSearch();
};
this.debounceReloadEditorComponent = debounce(
this.debounceReloadEditorComponent.bind(this),
25
);
}
deinit() {
@@ -180,10 +184,6 @@ export class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
this.reloadPreferences();
if (this.note.dirty) {
this.showSavingStatus();
}
if (this.editor.isTemplateNote) {
this.$timeout(() => {
this.focusTitle();
@@ -383,7 +383,7 @@ export class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
}
if (!this.note) return;
await this.reloadStackComponents();
await this.reloadEditorComponent();
this.debounceReloadEditorComponent();
}
);
}
@@ -410,6 +410,14 @@ export class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
});
}
/**
* Calling reloadEditorComponent successively without waiting for state to settle
* can result in componentViewers being dealloced twice
*/
debounceReloadEditorComponent() {
this.reloadEditorComponent();
}
private async reloadEditorComponent() {
const newEditor = this.application.componentManager.editorForNote(
this.note