Skip to content

Commit 007f52c

Browse files
committed
Feat(panels): each note can remember its own panels (#794)
The Connections, Outline, Comments and Calendar panels have always belonged to the pane: open the Outline and it stays open on every note you move to. That suits browsing, but #794 asks for the other habit, where a project note lives with its Outline and Connections open and a scratch note lives with nothing, and each comes back the way it was left. Panels following the pane stays the default, so nothing changes for anyone who does not ask. Turn off Settings > Editor > "Keep panels when switching notes" (or run "Remember Panels per Note" from the command palette) and each pane keeps one set of panels per note instead. A note you have not opened yet starts with none. It is the same shape as the per-note Edit / Split / Preview memory and its "Keep view mode" switch, on purpose: one idea, two settings that read alike. What it chooses: - The memory lasts for the session, like the per-note view mode. It is never written into the note, which is a plain file. If it should outlive a restart, the workspace snapshot that already restores tabs and layout is where it belongs; that is left for a follow-up. - A note's panels follow it through a rename or a move, are dropped when the note is deleted, and are copied to a new split. - Flipping the setting never rearranges the screen. The panels on view are carried into whichever store takes over, and only later note switches behave differently. - With the automatic calendar on, a daily or weekly note whose calendar you closed stays closed when you come back to it. That needs a "dismissed" bit, recorded only in per-note mode, so the default mode keeps auto-opening the calendar on every arrival exactly as before and the #502 state machine is untouched. - The preference is portable: `keep_panels_across_notes` under `[view]` in config.toml. EditorPane swaps its four useState calls for one hook, usePanePanels, with the same names and setter shapes, so every toggle and auto-open below it is unchanged. The setters keep a stable identity and read the live preference and path through refs, because the editor hands them to CodeMirror handlers that are built once per mount. The store action runs its updater outside zustand's set(): the panel toggles write to the store from inside their updater, and a write nested in a set() callback is clobbered when the callback returns. Both "Keep ..." settings also gain the Settings search entries and the sub-tab registration the older one never had, so searching for either opens the Writing tab on the right row. Closes #794
1 parent ecbc010 commit 007f52c

14 files changed

Lines changed: 555 additions & 9 deletions

File tree

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,15 @@ describe('TOML serialization', () => {
208208
expect(PORTABLE_PREF_KEYS.filter((key) => !(key in portable))).toEqual([])
209209
})
210210

211+
it('carries both keep-across-notes preferences', () => {
212+
const text = serializeConfig({ keepPanelsAcrossNotes: false, keepViewModeAcrossNotes: true })
213+
expect(text).toContain('keep_panels_across_notes = false')
214+
expect(text).toContain('keep_view_mode_across_notes = true')
215+
const { portable } = deserializeConfig(text)
216+
expect(portable.keepPanelsAcrossNotes).toBe(false)
217+
expect(portable.keepViewModeAcrossNotes).toBe(true)
218+
})
219+
211220
it('round-trips visual tweaks (colors + sliders) through the [tweaks] table', () => {
212221
const tweaks = { accent: '#ff3b30', density: 'comfortable', cornerRadius: 'rounded' }
213222
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
@@ -364,6 +364,11 @@ const SCALAR_FIELDS: Partial<Record<PortablePrefKey, ScalarFieldMap>> = {
364364
tomlKey: 'auto_calendar_panel',
365365
comment: 'auto-show the calendar for daily / weekly notes'
366366
},
367+
keepPanelsAcrossNotes: {
368+
section: 'view',
369+
tomlKey: 'keep_panels_across_notes',
370+
comment: 'true = Connections / Outline / Comments / Calendar stay as set while you switch notes; false = each note remembers its own panels for the session'
371+
},
367372
calendarWeekStart: {
368373
section: 'view',
369374
tomlKey: 'calendar_week_start',

‎packages/app-core/src/components/EditorPane.tsx‎

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,9 @@ import { isWorkspaceVirtualTabPath } from '../lib/workspace-tabs'
277277
import {
278278
CALENDAR_PANEL_CLOSED,
279279
calendarPanelOnNote,
280-
calendarPanelOnToggle,
281-
type CalendarPanelState
280+
calendarPanelOnToggle
282281
} from '../lib/calendar-panel-auto'
282+
import { usePanePanels } from '../lib/use-pane-panels'
283283
import {
284284
assetPathFromTab,
285285
assetTitleFromPath,
@@ -892,11 +892,21 @@ export function EditorPane({ pane }: { pane: PaneLeaf }): JSX.Element {
892892
keepViewModeAcrossNotes && paneStickyMode
893893
? paneStickyMode
894894
: paneModeForPath(modesByPath, activeTab, defaultPaneMode)
895-
const [connectionsOpen, setConnectionsOpen] = useState(false)
896-
const [outlineOpen, setOutlineOpen] = useState(false)
895+
// One sticky set per pane, or one per note when "Keep panels when switching
896+
// notes" is off (#794). Same names and setter shape as the four `useState`s
897+
// this replaced, so every toggle and auto-open below is unchanged.
898+
const {
899+
connections: connectionsOpen,
900+
outline: outlineOpen,
901+
comments: commentsOpen,
902+
calendar: calendarPanel,
903+
calendarAutoOpenAllowed,
904+
setConnectionsOpen,
905+
setOutlineOpen,
906+
setCommentsOpen,
907+
setCalendarPanel
908+
} = usePanePanels(paneId, activeTab)
897909
const [activeOutlineLine, setActiveOutlineLine] = useState<number | null>(null)
898-
const [commentsOpen, setCommentsOpen] = useState(false)
899-
const [calendarPanel, setCalendarPanel] = useState<CalendarPanelState>(CALENDAR_PANEL_CLOSED)
900910
const calendarOpen = calendarPanel.open
901911
// The calendar panel is a date navigator. It auto-opens while the pane shows
902912
// a daily/weekly note, but stays available (Obsidian-style) on any note as
@@ -1195,11 +1205,13 @@ export function EditorPane({ pane }: { pane: PaneLeaf }): JSX.Element {
11951205
setCalendarPanel((state) =>
11961206
calendarPanelOnNote(state, {
11971207
isDateNote,
1198-
autoEnabled: autoCalendarPanel,
1208+
// With panels kept per note, a calendar the user closed on this note
1209+
// stays closed when they come back to it. (#794)
1210+
autoEnabled: autoCalendarPanel && calendarAutoOpenAllowed,
11991211
available: calendarAvailable
12001212
})
12011213
)
1202-
}, [content?.path, isDateNote, autoCalendarPanel, calendarAvailable])
1214+
}, [content?.path, isDateNote, autoCalendarPanel, calendarAutoOpenAllowed, calendarAvailable])
12031215

12041216
useEffect(() => {
12051217
if (!isActive) return

‎packages/app-core/src/components/SettingsModal.tsx‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,8 @@ export function SettingsModal(): JSX.Element {
516516
const keepViewModeAcrossNotes = useStore((s) => s.keepViewModeAcrossNotes);
517517
const defaultPaneMode = useStore((s) => s.defaultPaneMode);
518518
const setDefaultPaneMode = useStore((s) => s.setDefaultPaneMode);
519+
const keepPanelsAcrossNotes = useStore((s) => s.keepPanelsAcrossNotes);
520+
const setKeepPanelsAcrossNotes = useStore((s) => s.setKeepPanelsAcrossNotes);
519521
const setKeepViewModeAcrossNotes = useStore(
520522
(s) => s.setKeepViewModeAcrossNotes,
521523
);
@@ -2046,6 +2048,30 @@ export function SettingsModal(): JSX.Element {
20462048
"loose",
20472049
],
20482050
},
2051+
{
2052+
id: "keep-view-mode",
2053+
title: "Keep view mode when switching notes",
2054+
description:
2055+
"Stay in the current Edit / Split / Preview mode when you open another note.",
2056+
keywords: ["view mode", "edit", "split", "preview", "sticky", "switch", "per note"],
2057+
},
2058+
{
2059+
id: "keep-panels",
2060+
title: "Keep panels when switching notes",
2061+
description:
2062+
"Connections, Outline, Comments and Calendar stay as you set them, or each note remembers its own.",
2063+
keywords: [
2064+
"panels",
2065+
"connections",
2066+
"outline",
2067+
"comments",
2068+
"calendar",
2069+
"sticky",
2070+
"per note",
2071+
"remember",
2072+
"switch",
2073+
],
2074+
},
20492075
{
20502076
id: "sync-title-heading-on-rename",
20512077
title: "Sync title heading on rename",
@@ -2477,6 +2503,8 @@ export function SettingsModal(): JSX.Element {
24772503
"render-tables",
24782504
"harper-enabled",
24792505
"harper-dialect",
2506+
"keep-view-mode",
2507+
"keep-panels",
24802508
"sync-title-heading-on-rename",
24812509
"markdown-overrides",
24822510
"heading-level-labels",
@@ -2609,6 +2637,13 @@ export function SettingsModal(): JSX.Element {
26092637
settingId="keep-view-mode"
26102638
onChange={setKeepViewModeAcrossNotes}
26112639
/>
2640+
<ToggleRow
2641+
label="Keep panels when switching notes"
2642+
description="Connections, Outline, Comments and Calendar stay as you set them while you move between notes. Turn off and each note remembers its own panels until you quit, so a note you have not opened yet starts with none."
2643+
value={keepPanelsAcrossNotes}
2644+
settingId="keep-panels"
2645+
onChange={setKeepPanelsAcrossNotes}
2646+
/>
26122647
<ToggleRow
26132648
label="Sync title heading on rename"
26142649
description="Renaming a note also rewrites its leading `# heading` to the new name, so the title line stops drifting from the filename. Only an existing top-level heading is rewritten — a note that opens with prose, a list, or a deeper heading is left alone, so deleting the `#` line opts that note out for good."

‎packages/app-core/src/folder-actions.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
44
import { databaseTabPath } from '@shared/databases'
55
import { parseTasksFromBody } from '@shared/tasks'
66
import { makeLeaf, allLeaves } from './lib/pane-layout'
7+
import { PANE_PANELS_CLOSED } from './lib/pane-panels'
78

89
beforeEach(() => {
910
vi.resetModules()
@@ -441,6 +442,7 @@ describe('folder mutation state', () => {
441442
s.useStore.setState({
442443
view: { kind: 'folder', folder: 'inbox', subpath: 'Work' },
443444
paneModes: { [state.activePaneId]: { [s.path]: 'preview' } },
445+
panePanels: { [state.activePaneId]: { [s.path]: { ...PANE_PANELS_CLOSED, outline: true } } },
444446
noteRefs: { [s.path]: { path: asset.path, kind: 'asset', fragment: 'page=2' } },
445447
manualNoteOrder: { Work: ['Work/Z.md', s.path] },
446448
vaultSettings: {
@@ -514,6 +516,7 @@ describe('folder mutation state', () => {
514516
expect(next.notes.some((n) => n.path.startsWith('Work/'))).toBe(false)
515517
expect(next.folders.some((f) => f.subpath === 'Work')).toBe(false)
516518
expect(next.paneModes[state.activePaneId][s.path]).toBeUndefined()
519+
expect(next.panePanels[state.activePaneId][s.path]).toBeUndefined()
517520
expect(next.noteRefs[s.path]).toBeUndefined()
518521
expect(next.manualNoteOrder.Work).toBeUndefined()
519522
expect(JSON.parse(localStorage.getItem('zen.notes.manualOrder./test')!)).toEqual(
@@ -522,6 +525,8 @@ describe('folder mutation state', () => {
522525
if (action === 'rename') {
523526
expect(next.view).toEqual({ kind: 'folder', folder: 'inbox', subpath: 'Renamed' })
524527
expect(next.paneModes[state.activePaneId]['Renamed/Note.md']).toBe('preview')
528+
// A note's remembered panels follow it through a rename too. (#794)
529+
expect(next.panePanels[state.activePaneId]['Renamed/Note.md']?.outline).toBe(true)
525530
expect(next.noteRefs['Renamed/Note.md']).toEqual({
526531
path: 'Renamed/image.png',
527532
kind: 'asset',

‎packages/app-core/src/lib/commands.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,6 +1495,15 @@ export function buildCommands(options?: { includeUnavailable?: boolean }): Comma
14951495
category: 'Editor',
14961496
run: () => getState().setTabsEnabled(!getState().tabsEnabled)
14971497
},
1498+
{
1499+
id: 'editor.keep-panels.toggle',
1500+
title: getState().keepPanelsAcrossNotes
1501+
? 'Remember Panels per Note'
1502+
: 'Keep Panels When Switching Notes',
1503+
category: 'Editor',
1504+
keywords: 'panels connections outline comments calendar sticky per note remember switch',
1505+
run: () => getState().setKeepPanelsAcrossNotes(!getState().keepPanelsAcrossNotes)
1506+
},
14981507
{
14991508
id: 'editor.word-wrap.toggle',
15001509
title: getState().wordWrap ? 'Disable Word Wrap' : 'Enable Word Wrap',

‎packages/app-core/src/lib/help.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const HELP_QUICK_START: HelpCard[] = [
7171
{
7272
title: 'Keep supporting material nearby',
7373
body:
74-
'Tabs, splits, floating windows, the reference pane, and the connections panel are all there to help you keep related material visible while you write instead of forcing constant back-and-forth navigation.'
74+
'Tabs, splits, floating windows, the reference pane, and the connections panel are all there to help you keep related material visible while you write instead of forcing constant back-and-forth navigation. The Connections, Outline, Comments and Calendar panels stay as you set them while you move between notes. If you would rather each note kept its own, turn off Settings → Editor → Keep panels when switching notes (or run Remember Panels per Note from the command palette): a note then comes back with the panels you left it with, until you quit, and a note you have not opened yet starts with none. With the automatic calendar on, a daily or weekly note whose calendar you closed stays closed when you return to it. The setting travels with your portable config as `keep_panels_across_notes` under `[view]`.'
7575
},
7676
{
7777
title: 'Use files without leaving ZenNotes',
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { describe, expect, it } from 'vitest'
2+
import { CALENDAR_PANEL_CLOSED } from './calendar-panel-auto'
3+
import {
4+
PANE_PANELS_CLOSED,
5+
panePanelsForPath,
6+
panePanelsWithPath,
7+
withCalendar,
8+
type PanePanelsState
9+
} from './pane-panels'
10+
11+
const outlineOpen: PanePanelsState = { ...PANE_PANELS_CLOSED, outline: true }
12+
13+
describe('per-note panels (#794)', () => {
14+
it('reads a note the pane has not seen yet as all closed', () => {
15+
expect(panePanelsForPath({}, 'inbox/A.md')).toEqual(PANE_PANELS_CLOSED)
16+
expect(panePanelsForPath({ 'inbox/A.md': outlineOpen }, 'inbox/B.md')).toEqual(
17+
PANE_PANELS_CLOSED
18+
)
19+
expect(panePanelsForPath({ 'inbox/A.md': outlineOpen }, null)).toEqual(PANE_PANELS_CLOSED)
20+
})
21+
22+
it('remembers each note separately', () => {
23+
const map = panePanelsWithPath({}, 'inbox/A.md', outlineOpen)
24+
expect(panePanelsForPath(map, 'inbox/A.md').outline).toBe(true)
25+
expect(panePanelsForPath(map, 'inbox/B.md').outline).toBe(false)
26+
})
27+
28+
it('returns the same map when nothing changed, so the store does not notify', () => {
29+
const map = { 'inbox/A.md': outlineOpen }
30+
expect(panePanelsWithPath(map, 'inbox/A.md', { ...outlineOpen })).toBe(map)
31+
expect(panePanelsWithPath(map, null, PANE_PANELS_CLOSED)).toBe(map)
32+
expect(panePanelsWithPath(map, 'inbox/B.md', PANE_PANELS_CLOSED)).toBe(map)
33+
})
34+
35+
it('drops a note whose panels are all closed instead of storing the default', () => {
36+
const map = panePanelsWithPath({ 'inbox/A.md': outlineOpen }, 'inbox/A.md', PANE_PANELS_CLOSED)
37+
expect(map).toEqual({})
38+
})
39+
40+
// Closed-by-the-user has to survive as an entry, or a daily note's calendar
41+
// would auto-open again every time you came back to it.
42+
it('keeps a note whose only memory is a calendar the user put away', () => {
43+
const open = withCalendar(PANE_PANELS_CLOSED, { open: true, auto: true }, true)
44+
const dismissed = withCalendar(open, CALENDAR_PANEL_CLOSED, true)
45+
expect(dismissed.calendarDismissed).toBe(true)
46+
expect(panePanelsWithPath({}, 'daily/today.md', dismissed)).toEqual({
47+
'daily/today.md': dismissed
48+
})
49+
})
50+
51+
it('forgets the dismissal as soon as the calendar is opened again', () => {
52+
const dismissed = { ...PANE_PANELS_CLOSED, calendarDismissed: true }
53+
expect(withCalendar(dismissed, { open: true, auto: false }, true).calendarDismissed).toBe(false)
54+
})
55+
56+
it('never records a dismissal for a sticky pane, whose auto-open keeps firing (#502)', () => {
57+
const open = withCalendar(PANE_PANELS_CLOSED, { open: true, auto: true }, false)
58+
expect(withCalendar(open, CALENDAR_PANEL_CLOSED, false).calendarDismissed).toBe(false)
59+
})
60+
})
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import { CALENDAR_PANEL_CLOSED, type CalendarPanelState } from './calendar-panel-auto'
2+
3+
/**
4+
* Which right-hand panels an editor pane shows: Connections, Outline, Comments
5+
* and the Calendar (whose open carries the provenance bit from #502).
6+
*
7+
* Panels have always been sticky per pane, Obsidian-style: open the Outline
8+
* and it stays while you browse. With "Keep panels when switching notes" off,
9+
* a pane instead remembers one of these per note, the way it already remembers
10+
* each note's Edit / Split / Preview mode (#794). Like those modes the memory
11+
* is for the session only. It never belongs in the note, which is a plain
12+
* file; if it should outlive a restart, the workspace snapshot that already
13+
* restores tabs and layout is where it goes.
14+
*/
15+
export interface PanePanelsState {
16+
connections: boolean
17+
outline: boolean
18+
comments: boolean
19+
calendar: CalendarPanelState
20+
/**
21+
* The user closed the calendar on this note. Only written per note: there it
22+
* keeps the auto-open for daily and weekly notes from reopening a calendar
23+
* the note was told to forget. A sticky pane never sets it, so its auto-open
24+
* keeps firing on every arrival at a date note, as it always has (#502).
25+
*/
26+
calendarDismissed: boolean
27+
}
28+
29+
export type PanePanelsByPath = Record<string, PanePanelsState>
30+
31+
/** A note the pane has not seen yet starts with nothing open. */
32+
export const PANE_PANELS_CLOSED: PanePanelsState = {
33+
connections: false,
34+
outline: false,
35+
comments: false,
36+
calendar: CALENDAR_PANEL_CLOSED,
37+
calendarDismissed: false
38+
}
39+
40+
export function samePanePanels(a: PanePanelsState, b: PanePanelsState): boolean {
41+
return (
42+
a.connections === b.connections &&
43+
a.outline === b.outline &&
44+
a.comments === b.comments &&
45+
a.calendar.open === b.calendar.open &&
46+
a.calendar.auto === b.calendar.auto &&
47+
a.calendarDismissed === b.calendarDismissed
48+
)
49+
}
50+
51+
export function panePanelsForPath(
52+
panelsByPath: PanePanelsByPath,
53+
path: string | null
54+
): PanePanelsState {
55+
return path ? panelsByPath[path] ?? PANE_PANELS_CLOSED : PANE_PANELS_CLOSED
56+
}
57+
58+
/**
59+
* The calendar after a write, with the per-note "dismissed" bit kept in step:
60+
* going from open to closed is the user (or Esc) putting it away on this note,
61+
* and any open clears that again.
62+
*/
63+
export function withCalendar(
64+
panels: PanePanelsState,
65+
calendar: CalendarPanelState,
66+
perNote: boolean
67+
): PanePanelsState {
68+
const calendarDismissed = calendar.open
69+
? false
70+
: perNote && panels.calendar.open
71+
? true
72+
: panels.calendarDismissed
73+
return { ...panels, calendar, calendarDismissed }
74+
}
75+
76+
/**
77+
* The map with `path` set to `panels`. A note whose panels are all closed is
78+
* dropped rather than stored, since closed is what an absent note reads as, so
79+
* the map only ever holds notes that differ from the default.
80+
*/
81+
export function panePanelsWithPath(
82+
panelsByPath: PanePanelsByPath,
83+
path: string | null,
84+
panels: PanePanelsState
85+
): PanePanelsByPath {
86+
if (!path) return panelsByPath
87+
const current = panelsByPath[path]
88+
if (samePanePanels(panels, PANE_PANELS_CLOSED)) {
89+
if (!current) return panelsByPath
90+
const { [path]: _dropped, ...rest } = panelsByPath
91+
return rest
92+
}
93+
if (current && samePanePanels(current, panels)) return panelsByPath
94+
return { ...panelsByPath, [path]: panels }
95+
}

0 commit comments

Comments
 (0)