feat: Switched editor appearance preferences to be local instead of synced (#2870)

This commit is contained in:
Aman Harwara
2024-04-24 12:24:34 +05:30
committed by GitHub
parent c402b66977
commit 594a6061b2
15 changed files with 120 additions and 73 deletions

View File

@@ -11,12 +11,12 @@ export const PrefDefaults = {
[PrefKey.NotesPanelWidth]: 350, [PrefKey.NotesPanelWidth]: 350,
[PrefKey.EditorWidth]: null, [PrefKey.EditorWidth]: null,
[PrefKey.EditorLeft]: null, [PrefKey.EditorLeft]: null,
[PrefKey.EditorMonospaceEnabled]: false, [PrefKey.DEPRECATED_EditorMonospaceEnabled]: false,
[PrefKey.EditorSpellcheck]: true, [PrefKey.EditorSpellcheck]: true,
[PrefKey.EditorResizersEnabled]: false, [PrefKey.EditorResizersEnabled]: false,
[PrefKey.EditorLineHeight]: EditorLineHeight.Normal, [PrefKey.DEPRECATED_EditorLineHeight]: EditorLineHeight.Normal,
[PrefKey.EditorLineWidth]: EditorLineWidth.FullWidth, [PrefKey.DEPRECATED_EditorLineWidth]: EditorLineWidth.FullWidth,
[PrefKey.EditorFontSize]: EditorFontSize.Normal, [PrefKey.DEPRECATED_EditorFontSize]: EditorFontSize.Normal,
[PrefKey.SortNotesBy]: CollectionSort.CreatedAt, [PrefKey.SortNotesBy]: CollectionSort.CreatedAt,
[PrefKey.SortNotesReverse]: false, [PrefKey.SortNotesReverse]: false,
[PrefKey.NotesShowArchived]: false, [PrefKey.NotesShowArchived]: false,

View File

@@ -12,12 +12,8 @@ export enum PrefKey {
NotesPanelWidth = 'notesPanelWidth', NotesPanelWidth = 'notesPanelWidth',
EditorWidth = 'editorWidth', EditorWidth = 'editorWidth',
EditorLeft = 'editorLeft', EditorLeft = 'editorLeft',
EditorMonospaceEnabled = 'monospaceFont',
EditorSpellcheck = 'spellcheck', EditorSpellcheck = 'spellcheck',
EditorResizersEnabled = 'marginResizersEnabled', EditorResizersEnabled = 'marginResizersEnabled',
EditorLineHeight = 'editorLineHeight',
EditorLineWidth = 'editorLineWidth',
EditorFontSize = 'editorFontSize',
SortNotesBy = 'sortBy', SortNotesBy = 'sortBy',
SortNotesReverse = 'sortReverse', SortNotesReverse = 'sortReverse',
NotesShowArchived = 'showArchived', NotesShowArchived = 'showArchived',
@@ -53,6 +49,10 @@ export enum PrefKey {
DEPRECATED_UseTranslucentUI = 'useTranslucentUI', DEPRECATED_UseTranslucentUI = 'useTranslucentUI',
DEPRECATED_AutoLightThemeIdentifier = 'autoLightThemeIdentifier', DEPRECATED_AutoLightThemeIdentifier = 'autoLightThemeIdentifier',
DEPRECATED_AutoDarkThemeIdentifier = 'autoDarkThemeIdentifier', DEPRECATED_AutoDarkThemeIdentifier = 'autoDarkThemeIdentifier',
DEPRECATED_EditorMonospaceEnabled = 'monospaceFont',
DEPRECATED_EditorLineHeight = 'editorLineHeight',
DEPRECATED_EditorLineWidth = 'editorLineWidth',
DEPRECATED_EditorFontSize = 'editorFontSize',
} }
export type PrefValue = { export type PrefValue = {
@@ -60,7 +60,6 @@ export type PrefValue = {
[PrefKey.NotesPanelWidth]: number [PrefKey.NotesPanelWidth]: number
[PrefKey.EditorWidth]: number | null [PrefKey.EditorWidth]: number | null
[PrefKey.EditorLeft]: number | null [PrefKey.EditorLeft]: number | null
[PrefKey.EditorMonospaceEnabled]: boolean
[PrefKey.EditorSpellcheck]: boolean [PrefKey.EditorSpellcheck]: boolean
[PrefKey.EditorResizersEnabled]: boolean [PrefKey.EditorResizersEnabled]: boolean
[PrefKey.SortNotesBy]: CollectionSortProperty [PrefKey.SortNotesBy]: CollectionSortProperty
@@ -81,9 +80,10 @@ export type PrefValue = {
[PrefKey.NoteAddToParentFolders]: boolean [PrefKey.NoteAddToParentFolders]: boolean
[PrefKey.NewNoteTitleFormat]: NewNoteTitleFormat [PrefKey.NewNoteTitleFormat]: NewNoteTitleFormat
[PrefKey.CustomNoteTitleFormat]: string [PrefKey.CustomNoteTitleFormat]: string
[PrefKey.EditorLineHeight]: EditorLineHeight [PrefKey.DEPRECATED_EditorMonospaceEnabled]: boolean
[PrefKey.EditorLineWidth]: EditorLineWidth [PrefKey.DEPRECATED_EditorLineHeight]: EditorLineHeight
[PrefKey.EditorFontSize]: EditorFontSize [PrefKey.DEPRECATED_EditorLineWidth]: EditorLineWidth
[PrefKey.DEPRECATED_EditorFontSize]: EditorFontSize
[PrefKey.UpdateSavingStatusIndicator]: boolean [PrefKey.UpdateSavingStatusIndicator]: boolean
[PrefKey.DefaultEditorIdentifier]: string [PrefKey.DefaultEditorIdentifier]: string
[PrefKey.MomentsDefaultTagUuid]: string | undefined [PrefKey.MomentsDefaultTagUuid]: string | undefined

View File

@@ -1,9 +1,16 @@
import { EditorFontSize, EditorLineHeight, EditorLineWidth } from '@standardnotes/models'
export enum LocalPrefKey { export enum LocalPrefKey {
ActiveThemes = 'activeThemes', ActiveThemes = 'activeThemes',
UseSystemColorScheme = 'useSystemColorScheme', UseSystemColorScheme = 'useSystemColorScheme',
UseTranslucentUI = 'useTranslucentUI', UseTranslucentUI = 'useTranslucentUI',
AutoLightThemeIdentifier = 'autoLightThemeIdentifier', AutoLightThemeIdentifier = 'autoLightThemeIdentifier',
AutoDarkThemeIdentifier = 'autoDarkThemeIdentifier', AutoDarkThemeIdentifier = 'autoDarkThemeIdentifier',
EditorMonospaceEnabled = 'monospaceFont',
EditorLineHeight = 'editorLineHeight',
EditorLineWidth = 'editorLineWidth',
EditorFontSize = 'editorFontSize',
} }
export type LocalPrefValue = { export type LocalPrefValue = {
@@ -12,4 +19,9 @@ export type LocalPrefValue = {
[LocalPrefKey.UseTranslucentUI]: boolean [LocalPrefKey.UseTranslucentUI]: boolean
[LocalPrefKey.AutoLightThemeIdentifier]: string [LocalPrefKey.AutoLightThemeIdentifier]: string
[LocalPrefKey.AutoDarkThemeIdentifier]: string [LocalPrefKey.AutoDarkThemeIdentifier]: string
[LocalPrefKey.EditorMonospaceEnabled]: boolean
[LocalPrefKey.EditorLineHeight]: EditorLineHeight
[LocalPrefKey.EditorLineWidth]: EditorLineWidth
[LocalPrefKey.EditorFontSize]: EditorFontSize
} }

View File

@@ -0,0 +1,45 @@
import { LocalPrefKey, ApplicationStage } from '@standardnotes/services'
import { Migration } from '@Lib/Migrations/Migration'
import { PrefDefaults, PrefKey } from '@standardnotes/models'
export class Migration2_209_0 extends Migration {
static override version(): string {
return '2.209.0'
}
protected registerStageHandlers(): void {
this.registerStageHandler(ApplicationStage.FullSyncCompleted_13, async () => {
await this.migrateSyncedPreferencesToLocal()
this.markDone()
})
}
private async migrateSyncedPreferencesToLocal(): Promise<void> {
this.services.preferences.setLocalValue(
LocalPrefKey.EditorMonospaceEnabled,
this.services.preferences.getValue(
PrefKey.DEPRECATED_EditorMonospaceEnabled,
PrefDefaults[LocalPrefKey.EditorMonospaceEnabled],
),
)
this.services.preferences.setLocalValue(
LocalPrefKey.EditorFontSize,
this.services.preferences.getValue(PrefKey.DEPRECATED_EditorFontSize, PrefDefaults[LocalPrefKey.EditorFontSize]),
)
this.services.preferences.setLocalValue(
LocalPrefKey.EditorLineWidth,
this.services.preferences.getValue(
PrefKey.DEPRECATED_EditorLineWidth,
PrefDefaults[LocalPrefKey.EditorLineWidth],
),
)
this.services.preferences.setLocalValue(
LocalPrefKey.EditorLineHeight,
this.services.preferences.getValue(
PrefKey.DEPRECATED_EditorLineHeight,
PrefDefaults[LocalPrefKey.EditorLineHeight],
),
)
}
}

View File

@@ -7,6 +7,7 @@ import { Migration2_167_6 } from './2_167_6'
import { Migration2_168_6 } from './2_168_6' import { Migration2_168_6 } from './2_168_6'
import { Migration2_202_1 } from './2_202_1' import { Migration2_202_1 } from './2_202_1'
import { Migration2_208_0 } from './2_208_0' import { Migration2_208_0 } from './2_208_0'
import { Migration2_209_0 } from './2_209_0'
export const MigrationClasses = [ export const MigrationClasses = [
Migration2_0_15, Migration2_0_15,
@@ -18,6 +19,7 @@ export const MigrationClasses = [
Migration2_168_6, Migration2_168_6,
Migration2_202_1, Migration2_202_1,
Migration2_208_0, Migration2_208_0,
Migration2_209_0,
] ]
export { export {
@@ -30,4 +32,5 @@ export {
Migration2_168_6, Migration2_168_6,
Migration2_202_1, Migration2_202_1,
Migration2_208_0, Migration2_208_0,
Migration2_209_0,
} }

View File

@@ -10,9 +10,9 @@ import {
IframeComponentFeatureDescription, IframeComponentFeatureDescription,
NoteMutator, NoteMutator,
NoteType, NoteType,
PrefKey,
SNNote, SNNote,
ContentType, ContentType,
LocalPrefKey,
} from '@standardnotes/snjs' } from '@standardnotes/snjs'
import { FunctionComponent, useCallback, useEffect, useState } from 'react' import { FunctionComponent, useCallback, useEffect, useState } from 'react'
import { EditorMenuGroup } from '@/Components/NotesOptions/EditorMenuGroup' import { EditorMenuGroup } from '@/Components/NotesOptions/EditorMenuGroup'
@@ -131,7 +131,7 @@ const ChangeEditorMenu: FunctionComponent<ChangeEditorMenuProps> = ({
setCurrentFeature(application.componentManager.editorForNote(note)) setCurrentFeature(application.componentManager.editorForNote(note))
if (uiFeature.featureIdentifier === NativeFeatureIdentifier.TYPES.PlainEditor) { if (uiFeature.featureIdentifier === NativeFeatureIdentifier.TYPES.PlainEditor) {
reloadFont(application.getPreference(PrefKey.EditorMonospaceEnabled)) reloadFont(application.preferences.getLocalValue(LocalPrefKey.EditorMonospaceEnabled))
} }
}, },
[application], [application],

View File

@@ -1,5 +1,5 @@
import { MutuallyExclusiveMediaQueryBreakpoints, useMediaQuery } from '@/Hooks/useMediaQuery' import { MutuallyExclusiveMediaQueryBreakpoints, useMediaQuery } from '@/Hooks/useMediaQuery'
import { classNames, EditorLineWidth, PrefKey, SNNote, PrefDefaults } from '@standardnotes/snjs' import { classNames, EditorLineWidth, SNNote, PrefDefaults, LocalPrefKey } from '@standardnotes/snjs'
import { useCallback, useEffect, useMemo, useState } from 'react' import { useCallback, useEffect, useMemo, useState } from 'react'
import Button from '../Button/Button' import Button from '../Button/Button'
import Modal, { ModalAction } from '../Modal/Modal' import Modal, { ModalAction } from '../Modal/Modal'
@@ -160,14 +160,14 @@ const EditorWidthSelectionModalWrapper = () => {
const lineWidth = note const lineWidth = note
? notesController.getEditorWidthForNote(note) ? notesController.getEditorWidthForNote(note)
: application.getPreference(PrefKey.EditorLineWidth, PrefDefaults[PrefKey.EditorLineWidth]) : application.preferences.getLocalValue(LocalPrefKey.EditorLineWidth, PrefDefaults[LocalPrefKey.EditorLineWidth])
const setLineWidth = useCallback( const setLineWidth = useCallback(
(lineWidth: EditorLineWidth, setGlobally: boolean) => { (lineWidth: EditorLineWidth, setGlobally: boolean) => {
if (note && !setGlobally) { if (note && !setGlobally) {
notesController.setNoteEditorWidth(note, lineWidth).catch(console.error) notesController.setNoteEditorWidth(note, lineWidth).catch(console.error)
} else { } else {
application.setPreference(PrefKey.EditorLineWidth, lineWidth).catch(console.error) application.preferences.setLocalValue(LocalPrefKey.EditorLineWidth, lineWidth)
} }
}, },
[application, note, notesController], [application, note, notesController],

View File

@@ -27,6 +27,7 @@ import {
ProposedSecondsToDeferUILevelSessionExpirationDuringActiveInteraction, ProposedSecondsToDeferUILevelSessionExpirationDuringActiveInteraction,
SNNote, SNNote,
VaultUserServiceEvent, VaultUserServiceEvent,
LocalPrefKey,
} from '@standardnotes/snjs' } from '@standardnotes/snjs'
import { confirmDialog, DELETE_NOTE_KEYBOARD_COMMAND, KeyboardKey } from '@standardnotes/ui-services' import { confirmDialog, DELETE_NOTE_KEYBOARD_COMMAND, KeyboardKey } from '@standardnotes/ui-services'
import { ChangeEventHandler, createRef, CSSProperties, FocusEvent, KeyboardEventHandler, RefObject } from 'react' import { ChangeEventHandler, createRef, CSSProperties, FocusEvent, KeyboardEventHandler, RefObject } from 'react'
@@ -123,7 +124,7 @@ class NoteView extends AbstractComponent<NoteViewProps, State> {
availableStackComponents: [], availableStackComponents: [],
editorStateDidLoad: false, editorStateDidLoad: false,
editorTitle: '', editorTitle: '',
editorLineWidth: PrefDefaults[PrefKey.EditorLineWidth], editorLineWidth: PrefDefaults[LocalPrefKey.EditorLineWidth],
isDesktop: isDesktopApplication(), isDesktop: isDesktopApplication(),
noteStatus: undefined, noteStatus: undefined,
noteLocked: this.controller.item.locked, noteLocked: this.controller.item.locked,
@@ -371,6 +372,7 @@ class NoteView extends AbstractComponent<NoteViewProps, State> {
} }
switch (eventName) { switch (eventName) {
case ApplicationEvent.LocalPreferencesChanged:
case ApplicationEvent.PreferencesChanged: case ApplicationEvent.PreferencesChanged:
void this.reloadPreferences() void this.reloadPreferences()
void this.reloadStackComponents() void this.reloadStackComponents()
@@ -673,9 +675,9 @@ class NoteView extends AbstractComponent<NoteViewProps, State> {
async reloadPreferences() { async reloadPreferences() {
log(LoggingDomain.NoteView, 'Reload preferences') log(LoggingDomain.NoteView, 'Reload preferences')
const monospaceFont = this.application.getPreference( const monospaceFont = this.application.preferences.getLocalValue(
PrefKey.EditorMonospaceEnabled, LocalPrefKey.EditorMonospaceEnabled,
PrefDefaults[PrefKey.EditorMonospaceEnabled], PrefDefaults[LocalPrefKey.EditorMonospaceEnabled],
) )
const updateSavingIndicator = this.application.getPreference( const updateSavingIndicator = this.application.getPreference(

View File

@@ -11,9 +11,9 @@ import {
EditorFontSize, EditorFontSize,
EditorLineHeight, EditorLineHeight,
isPayloadSourceRetrieved, isPayloadSourceRetrieved,
PrefKey,
WebAppEvent, WebAppEvent,
PrefDefaults, PrefDefaults,
LocalPrefKey,
} from '@standardnotes/snjs' } from '@standardnotes/snjs'
import { isIOS, TAB_COMMAND } from '@standardnotes/ui-services' import { isIOS, TAB_COMMAND } from '@standardnotes/ui-services'
import { import {
@@ -174,8 +174,14 @@ export const PlainEditor = forwardRef<PlainEditorInterface, Props>(
}, [controller, focusEditor]) }, [controller, focusEditor])
const reloadPreferences = useCallback(() => { const reloadPreferences = useCallback(() => {
const lineHeight = application.getPreference(PrefKey.EditorLineHeight, PrefDefaults[PrefKey.EditorLineHeight]) const lineHeight = application.preferences.getLocalValue(
const fontSize = application.getPreference(PrefKey.EditorFontSize, PrefDefaults[PrefKey.EditorFontSize]) LocalPrefKey.EditorLineHeight,
PrefDefaults[LocalPrefKey.EditorLineHeight],
)
const fontSize = application.preferences.getLocalValue(
LocalPrefKey.EditorFontSize,
PrefDefaults[LocalPrefKey.EditorFontSize],
)
setLineHeight(lineHeight) setLineHeight(lineHeight)
setFontSize(fontSize) setFontSize(fontSize)

View File

@@ -1,9 +1,9 @@
import { import {
ContentType, ContentType,
EditorLineHeightValues, EditorLineHeightValues,
LocalPrefKey,
NoteContent, NoteContent,
NoteType, NoteType,
PrefKey,
SNNote, SNNote,
classNames, classNames,
isUIFeatureAnIframeFeature, isUIFeatureAnIframeFeature,
@@ -17,7 +17,7 @@ import { BlocksEditor } from '../SuperEditor/BlocksEditor'
import { BlocksEditorComposer } from '../SuperEditor/BlocksEditorComposer' import { BlocksEditorComposer } from '../SuperEditor/BlocksEditorComposer'
import { useLinkingController } from '@/Controllers/LinkingControllerProvider' import { useLinkingController } from '@/Controllers/LinkingControllerProvider'
import LinkedItemBubblesContainer from '../LinkedItems/LinkedItemBubblesContainer' import LinkedItemBubblesContainer from '../LinkedItems/LinkedItemBubblesContainer'
import usePreference from '@/Hooks/usePreference' import { useLocalPreference } from '@/Hooks/usePreference'
import { useResponsiveEditorFontSize } from '@/Utils/getPlaintextFontSize' import { useResponsiveEditorFontSize } from '@/Utils/getPlaintextFontSize'
import { getScrollParent } from '@/Utils' import { getScrollParent } from '@/Utils'
@@ -132,8 +132,8 @@ export const ReadonlyNoteContent = ({
[note.noteType, onScroll, setScroller], [note.noteType, onScroll, setScroller],
) )
const lineHeight = usePreference(PrefKey.EditorLineHeight) const [lineHeight] = useLocalPreference(LocalPrefKey.EditorLineHeight)
const fontSize = usePreference(PrefKey.EditorFontSize) const [fontSize] = useLocalPreference(LocalPrefKey.EditorFontSize)
const responsiveFontSize = useResponsiveEditorFontSize(fontSize, false) const responsiveFontSize = useResponsiveEditorFontSize(fontSize, false)
return ( return (

View File

@@ -3,32 +3,23 @@ import Dropdown from '@/Components/Dropdown/Dropdown'
import Icon from '@/Components/Icon/Icon' import Icon from '@/Components/Icon/Icon'
import HorizontalSeparator from '@/Components/Shared/HorizontalSeparator' import HorizontalSeparator from '@/Components/Shared/HorizontalSeparator'
import Switch from '@/Components/Switch/Switch' import Switch from '@/Components/Switch/Switch'
import { import { EditorFontSize, EditorLineHeight, EditorLineWidth, LocalPrefKey } from '@standardnotes/snjs'
ApplicationEvent, import { useCallback, useMemo } from 'react'
EditorFontSize,
EditorLineHeight,
EditorLineWidth,
PrefKey,
PrefDefaults,
} from '@standardnotes/snjs'
import { useCallback, useEffect, useMemo, useState } from 'react'
import { Subtitle, Title, Text } from '../../PreferencesComponents/Content' import { Subtitle, Title, Text } from '../../PreferencesComponents/Content'
import PreferencesGroup from '../../PreferencesComponents/PreferencesGroup' import PreferencesGroup from '../../PreferencesComponents/PreferencesGroup'
import PreferencesSegment from '../../PreferencesComponents/PreferencesSegment' import PreferencesSegment from '../../PreferencesComponents/PreferencesSegment'
import { CHANGE_EDITOR_WIDTH_COMMAND } from '@standardnotes/ui-services' import { CHANGE_EDITOR_WIDTH_COMMAND } from '@standardnotes/ui-services'
import { useLocalPreference } from '../../../../Hooks/usePreference'
type Props = { type Props = {
application: WebApplication application: WebApplication
} }
const EditorDefaults = ({ application }: Props) => { const EditorDefaults = ({ application }: Props) => {
const [lineHeight, setLineHeight] = useState(() => const [lineHeight, setLineHeight] = useLocalPreference(LocalPrefKey.EditorLineHeight)
application.getPreference(PrefKey.EditorLineHeight, PrefDefaults[PrefKey.EditorLineHeight]),
)
const handleLineHeightChange = (value: string) => { const handleLineHeightChange = (value: string) => {
setLineHeight(value as EditorLineHeight) setLineHeight(value as EditorLineHeight)
void application.setPreference(PrefKey.EditorLineHeight, value as EditorLineHeight)
} }
const lineHeightDropdownOptions = useMemo( const lineHeightDropdownOptions = useMemo(
@@ -40,22 +31,14 @@ const EditorDefaults = ({ application }: Props) => {
[], [],
) )
const [monospaceFont, setMonospaceFont] = useState(() => const [monospaceFont, setMonospaceFont] = useLocalPreference(LocalPrefKey.EditorMonospaceEnabled)
application.getPreference(PrefKey.EditorMonospaceEnabled, PrefDefaults[PrefKey.EditorMonospaceEnabled]),
)
const toggleMonospaceFont = () => { const toggleMonospaceFont = () => {
setMonospaceFont(!monospaceFont) setMonospaceFont(!monospaceFont)
application.setPreference(PrefKey.EditorMonospaceEnabled, !monospaceFont).catch(console.error)
} }
const [fontSize, setFontSize] = useState(() => const [fontSize, setFontSize] = useLocalPreference(LocalPrefKey.EditorFontSize)
application.getPreference(PrefKey.EditorFontSize, PrefDefaults[PrefKey.EditorFontSize]),
)
const handleFontSizeChange = (value: string) => { const handleFontSizeChange = (value: string) => {
setFontSize(value as EditorFontSize) setFontSize(value as EditorFontSize)
void application.setPreference(PrefKey.EditorFontSize, value as EditorFontSize)
} }
const fontSizeDropdownOptions = useMemo( const fontSizeDropdownOptions = useMemo(
@@ -67,20 +50,12 @@ const EditorDefaults = ({ application }: Props) => {
[], [],
) )
const [editorWidth, setEditorWidth] = useState(() => const [editorWidth] = useLocalPreference(LocalPrefKey.EditorLineWidth)
application.getPreference(PrefKey.EditorLineWidth, PrefDefaults[PrefKey.EditorLineWidth]),
)
const toggleEditorWidthModal = useCallback(() => { const toggleEditorWidthModal = useCallback(() => {
application.keyboardService.triggerCommand(CHANGE_EDITOR_WIDTH_COMMAND, true) application.keyboardService.triggerCommand(CHANGE_EDITOR_WIDTH_COMMAND, true)
}, [application.keyboardService]) }, [application.keyboardService])
useEffect(() => {
return application.addSingleEventObserver(ApplicationEvent.PreferencesChanged, async () => {
setEditorWidth(application.getPreference(PrefKey.EditorLineWidth, PrefDefaults[PrefKey.EditorLineWidth]))
})
}, [application])
return ( return (
<PreferencesGroup> <PreferencesGroup>
<PreferencesSegment> <PreferencesSegment>

View File

@@ -1,9 +1,9 @@
import { BlocksEditor } from '@/Components/SuperEditor/BlocksEditor' import { BlocksEditor } from '@/Components/SuperEditor/BlocksEditor'
import { BlocksEditorComposer } from '@/Components/SuperEditor/BlocksEditorComposer' import { BlocksEditorComposer } from '@/Components/SuperEditor/BlocksEditorComposer'
import BlockPickerMenuPlugin from '@/Components/SuperEditor/Plugins/BlockPickerPlugin/BlockPickerPlugin' import BlockPickerMenuPlugin from '@/Components/SuperEditor/Plugins/BlockPickerPlugin/BlockPickerPlugin'
import usePreference from '@/Hooks/usePreference' import { useLocalPreference } from '@/Hooks/usePreference'
import { useResponsiveEditorFontSize } from '@/Utils/getPlaintextFontSize' import { useResponsiveEditorFontSize } from '@/Utils/getPlaintextFontSize'
import { EditorLineHeightValues, PrefKey, classNames } from '@standardnotes/snjs' import { EditorLineHeightValues, LocalPrefKey, classNames } from '@standardnotes/snjs'
import { CSSProperties, useRef, useState } from 'react' import { CSSProperties, useRef, useState } from 'react'
import { SuperDemoInitialValue } from './SuperDemoInitialValue' import { SuperDemoInitialValue } from './SuperDemoInitialValue'
import { UpgradePrompt } from './UpgradePrompt' import { UpgradePrompt } from './UpgradePrompt'
@@ -13,8 +13,8 @@ import { useAutoElementRect } from '@/Hooks/useElementRect'
const SuperDemo = ({ hasSubscription, onClose }: { hasSubscription: boolean; onClose: () => void }) => { const SuperDemo = ({ hasSubscription, onClose }: { hasSubscription: boolean; onClose: () => void }) => {
const application = useApplication() const application = useApplication()
const lineHeight = usePreference(PrefKey.EditorLineHeight) const [lineHeight] = useLocalPreference(LocalPrefKey.EditorLineHeight)
const fontSize = usePreference(PrefKey.EditorFontSize) const [fontSize] = useLocalPreference(LocalPrefKey.EditorFontSize)
const responsiveFontSize = useResponsiveEditorFontSize(fontSize, false) const responsiveFontSize = useResponsiveEditorFontSize(fontSize, false)
const ctaRef = useRef<HTMLButtonElement>(null) const ctaRef = useRef<HTMLButtonElement>(null)

View File

@@ -1,12 +1,12 @@
import { WebApplication } from '@/Application/WebApplication' import { WebApplication } from '@/Application/WebApplication'
import { import {
isPayloadSourceRetrieved, isPayloadSourceRetrieved,
PrefKey,
NativeFeatureIdentifier, NativeFeatureIdentifier,
FeatureStatus, FeatureStatus,
GetSuperNoteFeature, GetSuperNoteFeature,
EditorLineHeightValues, EditorLineHeightValues,
WebAppEvent, WebAppEvent,
LocalPrefKey,
} from '@standardnotes/snjs' } from '@standardnotes/snjs'
import { CSSProperties, FocusEvent, FunctionComponent, useCallback, useEffect, useRef, useState } from 'react' import { CSSProperties, FocusEvent, FunctionComponent, useCallback, useEffect, useRef, useState } from 'react'
import { BlocksEditor } from './BlocksEditor' import { BlocksEditor } from './BlocksEditor'
@@ -36,7 +36,7 @@ import ReadonlyPlugin from './Plugins/ReadonlyPlugin/ReadonlyPlugin'
import ModalOverlay from '@/Components/Modal/ModalOverlay' import ModalOverlay from '@/Components/Modal/ModalOverlay'
import NotEntitledBanner from '../ComponentView/NotEntitledBanner' import NotEntitledBanner from '../ComponentView/NotEntitledBanner'
import AutoFocusPlugin from './Plugins/AutoFocusPlugin' import AutoFocusPlugin from './Plugins/AutoFocusPlugin'
import usePreference from '@/Hooks/usePreference' import { useLocalPreference } from '@/Hooks/usePreference'
import BlockPickerMenuPlugin from './Plugins/BlockPickerPlugin/BlockPickerPlugin' import BlockPickerMenuPlugin from './Plugins/BlockPickerPlugin/BlockPickerPlugin'
import { EditorEventSource } from '@/Types/EditorEventSource' import { EditorEventSource } from '@/Types/EditorEventSource'
import { ElementIds } from '@/Constants/ElementIDs' import { ElementIds } from '@/Constants/ElementIDs'
@@ -194,8 +194,8 @@ export const SuperEditor: FunctionComponent<Props> = ({
return disposer return disposer
}, [controller, controller.item.uuid]) }, [controller, controller.item.uuid])
const lineHeight = usePreference(PrefKey.EditorLineHeight) const [lineHeight] = useLocalPreference(LocalPrefKey.EditorLineHeight)
const fontSize = usePreference(PrefKey.EditorFontSize) const [fontSize] = useLocalPreference(LocalPrefKey.EditorFontSize)
const responsiveFontSize = useResponsiveEditorFontSize(fontSize, false) const responsiveFontSize = useResponsiveEditorFontSize(fontSize, false)
const ref = useRef<HTMLDivElement>(null) const ref = useRef<HTMLDivElement>(null)

View File

@@ -1,5 +1,5 @@
import { WebApplication } from '@/Application/WebApplication' import { WebApplication } from '@/Application/WebApplication'
import { EditorLineHeightValues, NoteType, PrefKey, SNNote } from '@standardnotes/snjs' import { EditorLineHeightValues, LocalPrefKey, NoteType, SNNote } from '@standardnotes/snjs'
import { CSSProperties, FunctionComponent, useCallback, useEffect, useMemo, useState } from 'react' import { CSSProperties, FunctionComponent, useCallback, useEffect, useMemo, useState } from 'react'
import { ErrorBoundary } from '@/Utils/ErrorBoundary' import { ErrorBoundary } from '@/Utils/ErrorBoundary'
import ImportPlugin from './Plugins/ImportPlugin/ImportPlugin' import ImportPlugin from './Plugins/ImportPlugin/ImportPlugin'
@@ -8,7 +8,7 @@ import { spaceSeparatedStrings } from '@standardnotes/utils'
import Modal, { ModalAction } from '@/Components/Modal/Modal' import Modal, { ModalAction } from '@/Components/Modal/Modal'
import { BlocksEditor } from './BlocksEditor' import { BlocksEditor } from './BlocksEditor'
import { BlocksEditorComposer } from './BlocksEditorComposer' import { BlocksEditorComposer } from './BlocksEditorComposer'
import usePreference from '@/Hooks/usePreference' import { useLocalPreference } from '@/Hooks/usePreference'
import { useResponsiveEditorFontSize } from '@/Utils/getPlaintextFontSize' import { useResponsiveEditorFontSize } from '@/Utils/getPlaintextFontSize'
const NotePreviewCharLimit = 160 const NotePreviewCharLimit = 160
@@ -125,8 +125,8 @@ export const SuperNoteImporter: FunctionComponent<Props> = ({ note, application,
[canBeConvertedAsIs, closeDialog, confirmConvert, convertAsIs], [canBeConvertedAsIs, closeDialog, confirmConvert, convertAsIs],
) )
const lineHeight = usePreference(PrefKey.EditorLineHeight) const [lineHeight] = useLocalPreference(LocalPrefKey.EditorLineHeight)
const fontSize = usePreference(PrefKey.EditorFontSize) const [fontSize] = useLocalPreference(LocalPrefKey.EditorFontSize)
const responsiveFontSize = useResponsiveEditorFontSize(fontSize, false) const responsiveFontSize = useResponsiveEditorFontSize(fontSize, false)
if (isSeamlessConvert) { if (isSeamlessConvert) {

View File

@@ -27,6 +27,7 @@ import {
SyncServiceInterface, SyncServiceInterface,
AlertService, AlertService,
ProtectionsClientInterface, ProtectionsClientInterface,
LocalPrefKey,
} from '@standardnotes/snjs' } from '@standardnotes/snjs'
import { makeObservable, observable, action, computed, runInAction } from 'mobx' import { makeObservable, observable, action, computed, runInAction } from 'mobx'
import { AbstractViewController } from '../Abstract/AbstractViewController' import { AbstractViewController } from '../Abstract/AbstractViewController'
@@ -341,7 +342,10 @@ export class NotesController
} }
getEditorWidthForNote(note: SNNote) { getEditorWidthForNote(note: SNNote) {
return note.editorWidth ?? this.preferences.getValue(PrefKey.EditorLineWidth, PrefDefaults[PrefKey.EditorLineWidth]) return (
note.editorWidth ??
this.preferences.getLocalValue(LocalPrefKey.EditorLineWidth, PrefDefaults[LocalPrefKey.EditorLineWidth])
)
} }
async setNoteEditorWidth(note: SNNote, editorWidth: EditorLineWidth) { async setNoteEditorWidth(note: SNNote, editorWidth: EditorLineWidth) {