diff --git a/src/main/folder-workspace-diff-comments.ts b/src/main/folder-workspace-diff-comments.ts new file mode 100644 index 00000000000..1a7435e8930 --- /dev/null +++ b/src/main/folder-workspace-diff-comments.ts @@ -0,0 +1,37 @@ +import type { DiffComment, FolderWorkspace } from '../shared/types' + +// Why shape-only: this replaces folder-workspaces.ts's verbatim `Array.isArray(raw.diffComments)` read. +// Filtering members would make the fix itself a new deletion path for user-authored prose. +export function normalizeFolderWorkspaceDiffComments( + value: unknown +): Record | undefined { + if (typeof value !== 'object' || value === null || Array.isArray(value)) { + return undefined + } + const normalized: Record = {} + let kept = false + for (const [id, comments] of Object.entries(value)) { + if (!Array.isArray(comments)) { + continue + } + normalized[id] = comments as DiffComment[] + kept = true + } + return kept ? normalized : undefined +} + +// Why derive on every write: the map self-GCs, so delete paths need no pruning code. +export function collectFolderWorkspaceDiffComments( + workspaces: readonly FolderWorkspace[] | undefined +): Record | undefined { + const collected: Record = {} + let kept = false + for (const workspace of workspaces ?? []) { + const comments = workspace.diffComments + if (Array.isArray(comments) && comments.length > 0) { + collected[workspace.id] = comments + kept = true + } + } + return kept ? collected : undefined +} diff --git a/src/main/persistence.ts b/src/main/persistence.ts index 6f09f5ce025..a2e5d7b5499 100644 --- a/src/main/persistence.ts +++ b/src/main/persistence.ts @@ -55,7 +55,6 @@ import type { Repo, ProjectGroup, FolderWorkspace, - DiffComment, SparsePreset, PersistedMobileClientTabSelections, WorktreeMeta, @@ -257,6 +256,10 @@ import { normalizeUiLanguage } from '../shared/ui-language' import { normalizeBrowserPageZoomLevel } from '../shared/browser-page-zoom' import { persistedUIValuesEqual } from '../shared/persisted-ui-equality' import { ActiveViewPreference } from './active-view-preference' +import { + collectFolderWorkspaceDiffComments, + normalizeFolderWorkspaceDiffComments +} from './folder-workspace-diff-comments' import { normalizeFolderWorkspaceName, normalizeFolderWorkspaces @@ -429,42 +432,6 @@ function gcStaleWorktreeMeta(state: PersistedState): number { return removed } -// Why shape-only: this replaces folder-workspaces.ts's verbatim `Array.isArray(raw.diffComments)` read. -// Filtering members would make the fix itself a new deletion path for user-authored prose. -function normalizeFolderWorkspaceDiffComments( - value: unknown -): Record | undefined { - if (typeof value !== 'object' || value === null || Array.isArray(value)) { - return undefined - } - const normalized: Record = {} - let kept = false - for (const [id, comments] of Object.entries(value)) { - if (!Array.isArray(comments)) { - continue - } - normalized[id] = comments as DiffComment[] - kept = true - } - return kept ? normalized : undefined -} - -// Why derive on every write: the map self-GCs, so delete paths need no pruning code. -function collectFolderWorkspaceDiffComments( - workspaces: readonly FolderWorkspace[] | undefined -): Record | undefined { - const collected: Record = {} - let kept = false - for (const workspace of workspaces ?? []) { - const comments = workspace.diffComments - if (Array.isArray(comments) && comments.length > 0) { - collected[workspace.id] = comments - kept = true - } - } - return kept ? collected : undefined -} - function normalizeWorktreeLinkedItemMetadata(state: PersistedState): boolean { let changed = false const rawWorktreeMeta = state.worktreeMeta as unknown