Coerce any loaded prefs blob into a valid Prefs object, dropping * anything unknown (e.g. tokyo-night left over from earlier versions).
(p: Partial<Prefs>)
| 649 | /** Coerce any loaded prefs blob into a valid Prefs object, dropping |
| 650 | * anything unknown (e.g. tokyo-night left over from earlier versions). */ |
| 651 | function normalizePrefs(p: Partial<Prefs>): Prefs { |
| 652 | const themeFamily: ThemeFamily = |
| 653 | p.themeFamily && VALID_FAMILIES.includes(p.themeFamily) |
| 654 | ? p.themeFamily |
| 655 | : DEFAULT_PREFS.themeFamily |
| 656 | const themeMode: ThemeMode = |
| 657 | p.themeMode && VALID_MODES.includes(p.themeMode) |
| 658 | ? p.themeMode |
| 659 | : DEFAULT_PREFS.themeMode |
| 660 | const themeId = |
| 661 | p.themeId && (THEMES.some((t) => t.id === p.themeId) || isCustomThemeId(p.themeId)) |
| 662 | ? p.themeId |
| 663 | : DEFAULT_PREFS.themeId |
| 664 | return { |
| 665 | vimMode: typeof p.vimMode === 'boolean' ? p.vimMode : DEFAULT_PREFS.vimMode, |
| 666 | vimInsertEscape: |
| 667 | typeof p.vimInsertEscape === 'string' |
| 668 | ? p.vimInsertEscape.trim().slice(0, 5) |
| 669 | : DEFAULT_PREFS.vimInsertEscape, |
| 670 | vimYankToClipboard: |
| 671 | typeof p.vimYankToClipboard === 'boolean' |
| 672 | ? p.vimYankToClipboard |
| 673 | : DEFAULT_PREFS.vimYankToClipboard, |
| 674 | keymapOverrides: normalizeKeymapOverrides(p.keymapOverrides), |
| 675 | enabledOverrides: normalizeEnabledOverrides(p.enabledOverrides), |
| 676 | themeTweaks: normalizeThemeTweaks(p.themeTweaks), |
| 677 | whichKeyHints: |
| 678 | typeof p.whichKeyHints === 'boolean' |
| 679 | ? p.whichKeyHints |
| 680 | : DEFAULT_PREFS.whichKeyHints, |
| 681 | whichKeyHintMode: |
| 682 | p.whichKeyHintMode && VALID_WHICH_KEY_HINT_MODES.includes(p.whichKeyHintMode) |
| 683 | ? p.whichKeyHintMode |
| 684 | : DEFAULT_PREFS.whichKeyHintMode, |
| 685 | whichKeyHintTimeoutMs: |
| 686 | typeof p.whichKeyHintTimeoutMs === 'number' |
| 687 | ? Math.min(3000, Math.max(400, Math.round(p.whichKeyHintTimeoutMs))) |
| 688 | : DEFAULT_PREFS.whichKeyHintTimeoutMs, |
| 689 | vaultTextSearchBackend: |
| 690 | p.vaultTextSearchBackend && |
| 691 | VALID_VAULT_TEXT_SEARCH_BACKENDS.includes(p.vaultTextSearchBackend) |
| 692 | ? p.vaultTextSearchBackend |
| 693 | : DEFAULT_PREFS.vaultTextSearchBackend, |
| 694 | ripgrepBinaryPath: |
| 695 | typeof p.ripgrepBinaryPath === 'string' || p.ripgrepBinaryPath === null |
| 696 | ? (p.ripgrepBinaryPath as string | null) |
| 697 | : DEFAULT_PREFS.ripgrepBinaryPath, |
| 698 | fzfBinaryPath: |
| 699 | typeof p.fzfBinaryPath === 'string' || p.fzfBinaryPath === null |
| 700 | ? (p.fzfBinaryPath as string | null) |
| 701 | : DEFAULT_PREFS.fzfBinaryPath, |
| 702 | livePreview: |
| 703 | typeof p.livePreview === 'boolean' ? p.livePreview : DEFAULT_PREFS.livePreview, |
| 704 | renderTablesInLivePreview: |
| 705 | typeof p.renderTablesInLivePreview === 'boolean' |
| 706 | ? p.renderTablesInLivePreview |
| 707 | : DEFAULT_PREFS.renderTablesInLivePreview, |
| 708 | markdownSnippets: |
no test coverage detected