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

Function rewriteFolderColorsForRename

apps/desktop/src/main/vault.ts:1032–1053  ·  view source on GitHub ↗
(
  folderColors: Record<string, FolderColorId>,
  folder: NoteFolder,
  oldSubpath: string,
  newSubpath: string
)

Source from the content-addressed store, hash-verified

1030}
1031
1032function rewriteFolderColorsForRename(
1033 folderColors: Record<string, FolderColorId>,
1034 folder: NoteFolder,
1035 oldSubpath: string,
1036 newSubpath: string
1037): Record<string, FolderColorId> {
1038 const next: Record<string, FolderColorId> = {}
1039 const exactKey = folderIconKey(folder, oldSubpath)
1040 const prefix = `${exactKey}/`
1041 for (const [key, value] of Object.entries(folderColors)) {
1042 if (key === exactKey) {
1043 next[folderIconKey(folder, newSubpath)] = value
1044 continue
1045 }
1046 if (key.startsWith(prefix)) {
1047 next[folderIconKey(folder, newSubpath) + key.slice(exactKey.length)] = value
1048 continue
1049 }
1050 next[key] = value
1051 }
1052 return next
1053}
1054
1055function removeFolderColors(
1056 folderColors: Record<string, FolderColorId>,

Callers 1

renameFolderFunction · 0.70

Calls 1

folderIconKeyFunction · 0.70

Tested by

no test coverage detected