MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / persistCodeBlockFoldState

Function persistCodeBlockFoldState

packages/app-core/src/lib/code-block-copy.ts:152–171  ·  view source on GitHub ↗
(block: HTMLElement, folded: boolean)

Source from the content-addressed store, hash-verified

150}
151
152function persistCodeBlockFoldState(block: HTMLElement, folded: boolean): void {
153 const storageKey = block.getAttribute(CODE_BLOCK_STORAGE_KEY_ATTR)
154 const rawIndex = block.getAttribute(CODE_BLOCK_INDEX_ATTR)
155 const index = rawIndex == null ? Number.NaN : Number.parseInt(rawIndex, 10)
156 if (!storageKey || !Number.isFinite(index) || index < 0) return
157
158 const next = readFoldMap(storageKey)
159 if (folded) next[String(index)] = true
160 else delete next[String(index)]
161
162 try {
163 if (Object.keys(next).length > 0) {
164 window.localStorage.setItem(storageKey, JSON.stringify(next))
165 } else {
166 window.localStorage.removeItem(storageKey)
167 }
168 } catch {
169 // Persistence is best-effort; folding should still work without storage.
170 }
171}
172
173function readPersistedFoldState(storageKey: string, index: number): boolean | null {
174 const value = readFoldMap(storageKey)[String(index)]

Callers 1

toggleCodeBlockFoldFunction · 0.85

Calls 1

readFoldMapFunction · 0.85

Tested by

no test coverage detected