fix: correctly switch between editors

This commit is contained in:
Baptiste Grob
2020-08-19 12:31:42 +02:00
parent e201d438c1
commit ee837ea077
2 changed files with 13 additions and 10 deletions

View File

@@ -134,18 +134,18 @@
action="self.selectedMenuItem(true); self.toggleWebPrefKey(self.prefKeyMonospace)" action="self.selectedMenuItem(true); self.toggleWebPrefKey(self.prefKeyMonospace)"
circle="self.state.monospaceFont ? 'success' : 'neutral'", circle="self.state.monospaceFont ? 'success' : 'neutral'",
desc="'Toggles the font style for the default editor'", desc="'Toggles the font style for the default editor'",
disabled='self.activeEditorComponent', disabled='self.state.editorComponent',
label="'Monospace Font'", label="'Monospace Font'",
subtitle="self.activeEditorComponent ? 'Not available with editor extensions' : null" subtitle="self.state.editorComponent ? 'Not available with editor extensions' : null"
) )
menu-row( menu-row(
action="self.selectedMenuItem(true); self.toggleWebPrefKey(self.prefKeySpellcheck)" action="self.selectedMenuItem(true); self.toggleWebPrefKey(self.prefKeySpellcheck)"
circle="self.state.spellcheck ? 'success' : 'neutral'", circle="self.state.spellcheck ? 'success' : 'neutral'",
desc="'Toggles spellcheck for the default editor'", desc="'Toggles spellcheck for the default editor'",
disabled='self.activeEditorComponent', disabled='self.state.editorComponent',
label="'Spellcheck'", label="'Spellcheck'",
subtitle=` subtitle=`
self.activeEditorComponent self.state.editorComponent
? 'Not available with editor extensions' ? 'Not available with editor extensions'
: (self.state.isDesktop ? 'May degrade editor performance' : null) : (self.state.isDesktop ? 'May degrade editor performance' : null)
`) `)
@@ -167,7 +167,7 @@
callback='self.editorMenuOnSelect', callback='self.editorMenuOnSelect',
current-item='self.note', current-item='self.note',
ng-if='self.state.showEditorMenu', ng-if='self.state.showEditorMenu',
selected-editor-uuid='self.activeEditorComponent && self.activeEditorComponent.uuid', selected-editor-uuid='self.state.editorComponent && self.state.editorComponent.uuid',
application='self.application' application='self.application'
) )
.sk-app-bar-item( .sk-app-bar-item(
@@ -204,8 +204,8 @@
property="'left'" property="'left'"
) )
component-view.component-view( component-view.component-view(
component-uuid='self.activeEditorComponent.uuid', component-uuid='self.state.editorComponent.uuid',
ng-if='self.activeEditorComponent && !self.state.editorComponentUnloading', ng-if='self.state.editorComponent && !self.state.editorComponentUnloading',
on-load='self.onEditorLoad', on-load='self.onEditorLoad',
application='self.application' application='self.application'
) )
@@ -215,7 +215,7 @@
ng-change='self.contentChanged()', ng-change='self.contentChanged()',
ng-click='self.clickedTextArea()', ng-click='self.clickedTextArea()',
ng-focus='self.onContentFocus()', ng-focus='self.onContentFocus()',
ng-if='!self.activeEditorComponent && !self.state.textareaUnloading', ng-if='!self.state.editorComponent && !self.state.textareaUnloading',
ng-model='self.editorValues.text', ng-model='self.editorValues.text',
ng-model-options='{ debounce: self.state.editorDebounce}', ng-model-options='{ debounce: self.state.editorDebounce}',
ng-readonly='self.noteLocked', ng-readonly='self.noteLocked',

View File

@@ -344,21 +344,24 @@ 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) {
if (currentEditor) {
await this.application.componentManager!.deactivateComponent(currentEditor.uuid);
}
await this.setState({ await this.setState({
editorComponent: newEditor, 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) {
await this.application.componentManager?.activateComponent(newEditor.uuid); await this.application.componentManager!.activateComponent(newEditor.uuid);
} }
await this.setState({ await this.setState({
/** Reload component view */ /** Reload component view */
editorUnloading: false editorUnloading: false
}); });
this.reloadFont(); this.reloadFont();
this.application.componentManager!.contextItemDidChangeInArea(ComponentArea.Editor);
} }
this.application.componentManager!.contextItemDidChangeInArea(ComponentArea.Editor);
} }
setMenuState(menu: string, state: boolean) { setMenuState(menu: string, state: boolean) {