Merge pull request #421 from standardnotes/fix-editorview-options

fix: editor-view global display options
This commit is contained in:
Johnny A
2020-06-26 09:30:15 -04:00
committed by GitHub
2 changed files with 16 additions and 13 deletions

View File

@@ -132,7 +132,7 @@
.sk-menu-panel-header-title Global Display .sk-menu-panel-header-title Global Display
menu-row( menu-row(
action="self.selectedMenuItem(true); self.toggleWebPrefKey(self.prefKeyMonospace)" 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'", desc="'Toggles the font style for the default editor'",
disabled='self.activeEditorComponent', disabled='self.activeEditorComponent',
label="'Monospace Font'", label="'Monospace Font'",

View File

@@ -65,7 +65,7 @@ type EditorState = {
noteStatus?: NoteStatus noteStatus?: NoteStatus
tagsAsStrings?: string tagsAsStrings?: string
marginResizersEnabled?: boolean marginResizersEnabled?: boolean
monospaceEnabled?: boolean monospaceFont?: boolean
isDesktop?: boolean isDesktop?: boolean
syncTakingTooLong: boolean syncTakingTooLong: boolean
showExtensions: boolean showExtensions: boolean
@@ -77,7 +77,7 @@ type EditorState = {
/** Setting to false then true will allow the current editor component-view to be destroyed /** Setting to false then true will allow the current editor component-view to be destroyed
* then re-initialized. Used when changing between component editors. */ * then re-initialized. Used when changing between component editors. */
editorComponentUnloading: boolean 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. */ * then re-initialized. Used when reloading spellcheck status. */
textareaUnloading: boolean textareaUnloading: boolean
/** Fields that can be directly mutated by the template */ /** Fields that can be directly mutated by the template */
@@ -951,8 +951,8 @@ class EditorViewCtrl extends PureViewCtrl implements EditorViewScope {
this.application.getPrefsService().syncUserPreferences(); this.application.getPrefsService().syncUserPreferences();
} }
reloadPreferences() { async reloadPreferences() {
const monospaceEnabled = this.application.getPrefsService().getValue( const monospaceFont = this.application.getPrefsService().getValue(
WebPrefKey.EditorMonospaceEnabled, WebPrefKey.EditorMonospaceEnabled,
true true
); );
@@ -964,8 +964,8 @@ class EditorViewCtrl extends PureViewCtrl implements EditorViewScope {
WebPrefKey.EditorResizersEnabled, WebPrefKey.EditorResizersEnabled,
true true
); );
this.setEditorState({ await this.setEditorState({
monospaceEnabled, monospaceFont,
spellcheck, spellcheck,
marginResizersEnabled marginResizersEnabled
}); });
@@ -1008,7 +1008,7 @@ class EditorViewCtrl extends PureViewCtrl implements EditorViewScope {
if (!editor) { if (!editor) {
return; return;
} }
if (this.getState().monospaceEnabled) { if (this.getState().monospaceFont) {
if (this.getState().isDesktop) { if (this.getState().isDesktop) {
editor.style.fontFamily = Fonts.DesktopMonospaceFamily; editor.style.fontFamily = Fonts.DesktopMonospaceFamily;
} else { } else {
@@ -1020,20 +1020,23 @@ class EditorViewCtrl extends PureViewCtrl implements EditorViewScope {
} }
async toggleWebPrefKey(key: WebPrefKey) { async toggleWebPrefKey(key: WebPrefKey) {
(this as any)[key] = !(this as any)[key]; const currentValue = this.state[key];
this.application.getPrefsService().setUserPrefValue( await this.application.getPrefsService().setUserPrefValue(
key, key,
(this as any)[key], !currentValue,
true true
); );
await this.setEditorState({
[key]: !currentValue
})
this.reloadFont(); this.reloadFont();
if (key === WebPrefKey.EditorSpellcheck) { if (key === WebPrefKey.EditorSpellcheck) {
/** Allows textarea to reload */ /** Allows textarea to reload */
await this.setEditorState({ textareaUnloading: true });
await this.setEditorState({ textareaUnloading: false }); await this.setEditorState({ textareaUnloading: false });
this.setEditorState({ textareaUnloading: true });
this.reloadFont(); this.reloadFont();
} else if (key === WebPrefKey.EditorResizersEnabled && (this as any)[key] === true) { } else if (key === WebPrefKey.EditorResizersEnabled && this.state[key] === true) {
this.$timeout(() => { this.$timeout(() => {
this.leftPanelPuppet!.flash!(); this.leftPanelPuppet!.flash!();
this.rightPanelPuppet!.flash!(); this.rightPanelPuppet!.flash!();