Skip to content

Commit ecbc010

Browse files
committed
Fix(config): "Keep view mode when switching notes" travels in config.toml
`keepViewModeAcrossNotes` has been in PORTABLE_PREF_KEYS since it shipped (#543), which is the list of preferences that are supposed to travel between machines in `~/.config/zennotes/config.toml`. It never did. The desktop writer only emits keys that have a field mapping, the key had none, so it was portable in name only: set it on one machine and the file, and every other machine reading that file, never heard about it. It is now `keep_view_mode_across_notes` under `[editor]`. A key missing from an existing file keeps the local value when the file is read, so nobody's current choice is reset; the option simply appears in the file the next time the app rewrites it. To keep this from happening to the next preference, a test now requires every key in PORTABLE_PREF_KEYS to come back out of a freshly written config. Without the mapping it fails and names the key.
1 parent c048134 commit ecbc010

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

‎apps/desktop/src/main/app-config.test.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
ensureConfigFile,
2929
stopAppConfigWatcher
3030
} from './app-config'
31-
import { CONFIG_VERSION, type AppConfigPortable } from '@shared/app-config'
31+
import { CONFIG_VERSION, PORTABLE_PREF_KEYS, type AppConfigPortable } from '@shared/app-config'
3232

3333
const tempDirs: string[] = []
3434
async function tmp(prefix: string): Promise<string> {
@@ -200,6 +200,14 @@ describe('TOML serialization', () => {
200200
expect(portable.ripgrepBinaryPath).toBeNull()
201201
})
202202

203+
// `keepViewModeAcrossNotes` sat in PORTABLE_PREF_KEYS for months with no
204+
// field mapping, so it was "portable" in name only and never reached the
205+
// file. Every portable key has to come back out of a freshly written config.
206+
it('maps every portable preference into the file, so none stays on one machine', () => {
207+
const { portable } = deserializeConfig(serializeConfig({}))
208+
expect(PORTABLE_PREF_KEYS.filter((key) => !(key in portable))).toEqual([])
209+
})
210+
203211
it('round-trips visual tweaks (colors + sliders) through the [tweaks] table', () => {
204212
const tweaks = { accent: '#ff3b30', density: 'comfortable', cornerRadius: 'rounded' }
205213
const text = serializeConfig({ themeTweaks: tweaks })

‎apps/desktop/src/main/app-config.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,11 @@ const SCALAR_FIELDS: Partial<Record<PortablePrefKey, ScalarFieldMap>> = {
225225
tomlKey: 'default_view_mode',
226226
comment: 'edit | split | preview — the mode a note opens in before it has a remembered one'
227227
},
228+
keepViewModeAcrossNotes: {
229+
section: 'editor',
230+
tomlKey: 'keep_view_mode_across_notes',
231+
comment: 'true = stay in the current Edit / Split / Preview mode when opening another note; false = each note reopens in its own last mode'
232+
},
228233
lineNumberMode: {
229234
section: 'editor',
230235
tomlKey: 'line_number_mode',

0 commit comments

Comments
 (0)