From b944f3dec8099e1086071feaa3ab7da2d7ea85e6 Mon Sep 17 00:00:00 2001 From: Johnny Almonte Date: Wed, 24 Jun 2020 23:47:40 -0400 Subject: [PATCH 1/5] fix: read preferences value from state --- .../javascripts/views/editor/editor_view.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/views/editor/editor_view.ts b/app/assets/javascripts/views/editor/editor_view.ts index 6d118ff53..9d8904f9a 100644 --- a/app/assets/javascripts/views/editor/editor_view.ts +++ b/app/assets/javascripts/views/editor/editor_view.ts @@ -951,7 +951,7 @@ class EditorViewCtrl extends PureViewCtrl implements EditorViewScope { this.application.getPrefsService().syncUserPreferences(); } - reloadPreferences() { + async reloadPreferences() { const monospaceEnabled = this.application.getPrefsService().getValue( WebPrefKey.EditorMonospaceEnabled, true @@ -964,7 +964,7 @@ class EditorViewCtrl extends PureViewCtrl implements EditorViewScope { WebPrefKey.EditorResizersEnabled, true ); - this.setEditorState({ + await this.setEditorState({ monospaceEnabled, spellcheck, marginResizersEnabled @@ -1020,12 +1020,15 @@ class EditorViewCtrl extends PureViewCtrl implements EditorViewScope { } async toggleWebPrefKey(key: WebPrefKey) { - (this as any)[key] = !(this as any)[key]; - this.application.getPrefsService().setUserPrefValue( + const currentValue = this.state[key]; + await this.application.getPrefsService().setUserPrefValue( key, - (this as any)[key], + !currentValue, true ); + await this.setEditorState({ + [key]: !currentValue + }) this.reloadFont(); if (key === WebPrefKey.EditorSpellcheck) { @@ -1033,7 +1036,7 @@ class EditorViewCtrl extends PureViewCtrl implements EditorViewScope { await this.setEditorState({ textareaUnloading: false }); this.setEditorState({ textareaUnloading: true }); this.reloadFont(); - } else if (key === WebPrefKey.EditorResizersEnabled && (this as any)[key] === true) { + } else if (key === WebPrefKey.EditorResizersEnabled && this.state[key] === true) { this.$timeout(() => { this.leftPanelPuppet!.flash!(); this.rightPanelPuppet!.flash!(); From 72de9516b8b740756236d82301f22e681dbec3c7 Mon Sep 17 00:00:00 2001 From: Johnny Almonte Date: Wed, 24 Jun 2020 23:51:41 -0400 Subject: [PATCH 2/5] fix: 'Spellcheck' option removes note editor from view --- app/assets/javascripts/views/editor/editor_view.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/views/editor/editor_view.ts b/app/assets/javascripts/views/editor/editor_view.ts index 9d8904f9a..0482a7a6a 100644 --- a/app/assets/javascripts/views/editor/editor_view.ts +++ b/app/assets/javascripts/views/editor/editor_view.ts @@ -1033,8 +1033,8 @@ class EditorViewCtrl extends PureViewCtrl implements EditorViewScope { if (key === WebPrefKey.EditorSpellcheck) { /** Allows textarea to reload */ + await this.setEditorState({ textareaUnloading: true }); await this.setEditorState({ textareaUnloading: false }); - this.setEditorState({ textareaUnloading: true }); this.reloadFont(); } else if (key === WebPrefKey.EditorResizersEnabled && this.state[key] === true) { this.$timeout(() => { From ce40cc4ba17a01166413e907db5b65913c233c45 Mon Sep 17 00:00:00 2001 From: Johnny Almonte Date: Thu, 25 Jun 2020 11:07:44 -0400 Subject: [PATCH 3/5] fix: correct monospace state name --- app/assets/javascripts/views/editor/editor_view.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/views/editor/editor_view.ts b/app/assets/javascripts/views/editor/editor_view.ts index 0482a7a6a..fec38617d 100644 --- a/app/assets/javascripts/views/editor/editor_view.ts +++ b/app/assets/javascripts/views/editor/editor_view.ts @@ -65,7 +65,7 @@ type EditorState = { noteStatus?: NoteStatus tagsAsStrings?: string marginResizersEnabled?: boolean - monospaceEnabled?: boolean + monospaceFont?: boolean isDesktop?: boolean syncTakingTooLong: boolean showExtensions: boolean @@ -952,7 +952,7 @@ class EditorViewCtrl extends PureViewCtrl implements EditorViewScope { } async reloadPreferences() { - const monospaceEnabled = this.application.getPrefsService().getValue( + const monospaceFont = this.application.getPrefsService().getValue( WebPrefKey.EditorMonospaceEnabled, true ); @@ -965,7 +965,7 @@ class EditorViewCtrl extends PureViewCtrl implements EditorViewScope { true ); await this.setEditorState({ - monospaceEnabled, + monospaceFont, spellcheck, marginResizersEnabled }); @@ -1008,7 +1008,7 @@ class EditorViewCtrl extends PureViewCtrl implements EditorViewScope { if (!editor) { return; } - if (this.getState().monospaceEnabled) { + if (this.getState().monospaceFont) { if (this.getState().isDesktop) { editor.style.fontFamily = Fonts.DesktopMonospaceFamily; } else { From 159f8f381cb4e5bbe5ef57e26d784694ec6e9807 Mon Sep 17 00:00:00 2001 From: Johnny Almonte Date: Thu, 25 Jun 2020 11:08:27 -0400 Subject: [PATCH 4/5] fix: update comment for textareaUnloading --- app/assets/javascripts/views/editor/editor_view.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/views/editor/editor_view.ts b/app/assets/javascripts/views/editor/editor_view.ts index fec38617d..90dc822c4 100644 --- a/app/assets/javascripts/views/editor/editor_view.ts +++ b/app/assets/javascripts/views/editor/editor_view.ts @@ -77,7 +77,7 @@ type EditorState = { /** Setting to false then true will allow the current editor component-view to be destroyed * then re-initialized. Used when changing between component editors. */ editorComponentUnloading: boolean - /** Setting to false then true will allow the main content textarea to be destroyed + /** Setting to true then false will allow the main content textarea to be destroyed * then re-initialized. Used when reloading spellcheck status. */ textareaUnloading: boolean /** Fields that can be directly mutated by the template */ From a75f1b8d526e9d1ace87c6a212ae846a3c36d470 Mon Sep 17 00:00:00 2001 From: Johnny Almonte Date: Thu, 25 Jun 2020 11:11:14 -0400 Subject: [PATCH 5/5] fix: update monospaceFont in editor template --- app/assets/javascripts/views/editor/editor-view.pug | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/views/editor/editor-view.pug b/app/assets/javascripts/views/editor/editor-view.pug index cca72cd54..00372964c 100644 --- a/app/assets/javascripts/views/editor/editor-view.pug +++ b/app/assets/javascripts/views/editor/editor-view.pug @@ -132,7 +132,7 @@ .sk-menu-panel-header-title Global Display menu-row( action="self.selectedMenuItem(true); self.toggleWebPrefKey(self.prefKeyMonospace)" - circle="self.state.monospaceEnabled ? 'success' : 'neutral'", + circle="self.state.monospaceFont ? 'success' : 'neutral'", desc="'Toggles the font style for the default editor'", disabled='self.activeEditorComponent', label="'Monospace Font'",