( map: Record<string, T>, folder: NoteFolder, oldSubpath: string, newSubpath: string )
| 698 | // so renames/deletes/duplicates rewrite them identically. Generic helpers keep |
| 699 | // the two in lock-step without duplicating the traversal logic. |
| 700 | function rewriteFolderKeyMap<T>( |
| 701 | map: Record<string, T>, |
| 702 | folder: NoteFolder, |
| 703 | oldSubpath: string, |
| 704 | newSubpath: string |
| 705 | ): Record<string, T> { |
| 706 | const next: Record<string, T> = {} |
| 707 | const exactKey = folderIconKey(folder, oldSubpath) |
| 708 | const prefix = `${exactKey}/` |
| 709 | for (const [key, value] of Object.entries(map)) { |
| 710 | if (key === exactKey) { |
| 711 | next[folderIconKey(folder, newSubpath)] = value |
| 712 | continue |
| 713 | } |
| 714 | if (key.startsWith(prefix)) { |
| 715 | next[folderIconKey(folder, newSubpath) + key.slice(exactKey.length)] = value |
| 716 | continue |
| 717 | } |
| 718 | next[key] = value |
| 719 | } |
| 720 | return next |
| 721 | } |
| 722 | |
| 723 | function removeFolderKeyMap<T>( |
| 724 | map: Record<string, T>, |
no test coverage detected