diff --git a/app/assets/javascripts/views/editor/editor_view.ts b/app/assets/javascripts/views/editor/editor_view.ts index 23ddc4409..6f96c0df3 100644 --- a/app/assets/javascripts/views/editor/editor_view.ts +++ b/app/assets/javascripts/views/editor/editor_view.ts @@ -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 { this.onEditorLoad = () => { this.application.getDesktopService().redoSearch(); }; + this.debounceReloadEditorComponent = debounce( + this.debounceReloadEditorComponent.bind(this), + 25 + ); } deinit() { @@ -180,10 +184,6 @@ export class EditorViewCtrl extends PureViewCtrl { 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 { } if (!this.note) return; await this.reloadStackComponents(); - await this.reloadEditorComponent(); + this.debounceReloadEditorComponent(); } ); } @@ -410,6 +410,14 @@ export class EditorViewCtrl extends PureViewCtrl { }); } + /** + * 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