| @@ -25,7 +25,6 @@ import { |
| 25 | onKeyStroke, |
25 | onKeyStroke, |
| 26 | useElementBounding, |
26 | useElementBounding, |
| 27 | useEventListener, |
27 | useEventListener, |
| 28 | useLocalStorage, |
| |
| 29 | useScrollLock, |
28 | useScrollLock, |
| 30 | useSessionStorage, |
29 | useSessionStorage, |
| 31 | watchDebounced |
30 | watchDebounced |
| @@ -45,6 +44,7 @@ import { |
| 45 | Clock, |
44 | Clock, |
| 46 | File, |
45 | File, |
| 47 | Globe, |
46 | Globe, |
| |
47 | Highlighter, |
| 48 | Hash, |
48 | Hash, |
| 49 | Layers, |
49 | Layers, |
| 50 | LayoutList, |
50 | LayoutList, |
| @@ -65,6 +65,16 @@ import { useData } from '../composables/search/use-data' |
| 65 | import { useEffects } from '../composables/useEffects' |
65 | import { useEffects } from '../composables/useEffects' |
| 66 | import { applyFavicons, useFavicons } from '../composables/useFavicons' |
66 | import { applyFavicons, useFavicons } from '../composables/useFavicons' |
| 67 | import { registerGlobalComponents } from '../globalComponents' |
67 | import { registerGlobalComponents } from '../globalComponents' |
| |
68 | import { |
| |
69 | excerptPreload, |
| |
70 | saveHistoryEnabled, |
| |
71 | searchHistory, |
| |
72 | searchMode, |
| |
73 | searchResultHighlightMode, |
| |
74 | showDetailedList, |
| |
75 | type SearchHistoryEntry, |
| |
76 | type SearchSortMode |
| |
77 | } from '../searchState' |
| 68 | import { enhanceAppWithTabs } from './tabs' |
78 | import { enhanceAppWithTabs } from './tabs' |
| 69 | |
79 | |
| 70 | export interface FooterTranslations { |
80 | export interface FooterTranslations { |
| @@ -265,23 +275,6 @@ watch(filterText, (v) => { |
| 265 | }) |
275 | }) |
| 266 | onBeforeUnmount(() => clearTimeout(urlDebounceTimer)) |
276 | onBeforeUnmount(() => clearTimeout(urlDebounceTimer)) |
| 267 | |
277 | |
| 268 | const showDetailedList = useLocalStorage( |
| |
| 269 | 'vitepress:local-search-detailed-list', |
| |
| 270 | true |
| |
| 271 | ) |
| |
| 272 | |
| |
| 273 | // Three search modes: 'exact' | 'fuzzy' | 'url' |
| |
| 274 | const searchMode = useLocalStorage<'exact' | 'fuzzy' | 'url'>( |
| |
| 275 | 'vitepress:local-search-mode', |
| |
| 276 | 'exact' |
| |
| 277 | ) |
| |
| 278 | |
| |
| 279 | // How many result pages get their excerpts rendered ahead of time |
| |
| 280 | const excerptPreload = useLocalStorage<'off' | 'next' | 'all'>( |
| |
| 281 | 'vitepress:local-search-excerpt-preload', |
| |
| 282 | 'off' |
| |
| 283 | ) |
| |
| 284 | |
| |
| 285 | // Cycle through modes on mobile (only active button is visible, tap it to advance) |
278 | // Cycle through modes on mobile (only active button is visible, tap it to advance) |
| 286 | function cycleSearchMode() { |
279 | function cycleSearchMode() { |
| 287 | const modes = ['exact', 'fuzzy', 'url'] as const |
280 | const modes = ['exact', 'fuzzy', 'url'] as const |
| @@ -293,31 +286,22 @@ function cycleSearchMode() { |
| 293 | const matchExact = computed(() => searchMode.value === 'exact') |
286 | const matchExact = computed(() => searchMode.value === 'exact') |
| 294 | const urlSearchMode = computed(() => searchMode.value === 'url') |
287 | const urlSearchMode = computed(() => searchMode.value === 'url') |
| 295 | |
288 | |
| 296 | // Search history |
| |
| 297 | interface SearchHistoryEntry { |
| |
| 298 | query: string |
| |
| 299 | mode: SearchMode |
| |
| 300 | path?: string[] |
| |
| 301 | href?: string |
| |
| 302 | } |
| |
| 303 | |
| |
| 304 | const saveHistoryEnabled = useLocalStorage('vitepress:local-search-save-history', false) |
| |
| 305 | |
| |
| 306 | const searchHistory = useLocalStorage<SearchHistoryEntry[]>( |
| |
| 307 | 'vitepress:local-search-history', |
| |
| 308 | [] |
| |
| 309 | ) |
| |
| 310 | |
| |
| 311 | const showHistory = computed( |
289 | const showHistory = computed( |
| 312 | () => !filterText.value && searchHistory.value.length > 0 |
290 | () => !filterText.value && searchHistory.value.length > 0 |
| 313 | ) |
291 | ) |
| 314 | |
292 | |
| 315 | function saveToHistory(query: string, mode: SearchMode, path?: string[], href?: string) { |
293 | function saveToHistory( |
| |
294 | query: string, |
| |
295 | mode: SearchSortMode, |
| |
296 | path?: string[], |
| |
297 | href?: string, |
| |
298 | resultText?: string |
| |
299 | ) { |
| 316 | const trimmed = query.trim() |
300 | const trimmed = query.trim() |
| 317 | if (!trimmed || !saveHistoryEnabled.value) return |
301 | if (!trimmed || !saveHistoryEnabled.value) return |
| 318 | const pathKey = (path ?? []).join('\n') |
302 | const pathKey = (path ?? []).join('\n') |
| 319 | searchHistory.value = [ |
303 | searchHistory.value = [ |
| 320 | { query: trimmed, mode, path, href }, |
304 | { query: trimmed, mode, path, href, resultText }, |
| 321 | ...searchHistory.value.filter( |
305 | ...searchHistory.value.filter( |
| 322 | (h) => !(h.query === trimmed && h.mode === mode && (h.path ?? []).join('\n') === pathKey) |
306 | (h) => !(h.query === trimmed && h.mode === mode && (h.path ?? []).join('\n') === pathKey) |
| 323 | ) |
307 | ) |
| @@ -331,7 +315,9 @@ function removeFromHistory(index: number) { |
| 331 | function applyHistory(entry: SearchHistoryEntry) { |
315 | function applyHistory(entry: SearchHistoryEntry) { |
| 332 | if (entry.href) { |
316 | if (entry.href) { |
| 333 | window.dispatchEvent( |
317 | window.dispatchEvent( |
| 334 | new CustomEvent('search-nav', { detail: { query: entry.query } }) |
318 | new CustomEvent('search-nav', { |
| |
319 | detail: { query: entry.query, resultText: entry.resultText } |
| |
320 | }) |
| 335 | ) |
321 | ) |
| 336 | router.go(entry.href) |
322 | router.go(entry.href) |
| 337 | showSearch.value = false |
323 | showSearch.value = false |
| @@ -347,7 +333,12 @@ const showSettingsPopup = ref(false) |
| 347 | const settingsButtonRef = ref<HTMLButtonElement>() |
333 | const settingsButtonRef = ref<HTMLButtonElement>() |
| 348 | const settingsPopupRef = ref<HTMLDivElement>() |
334 | const settingsPopupRef = ref<HTMLDivElement>() |
| 349 | const settingsBounding = useElementBounding(settingsButtonRef) |
335 | const settingsBounding = useElementBounding(settingsButtonRef) |
| 350 | type HelpSection = 'search' | 'view' | 'preload' | 'history' |
336 | type HelpSection = |
| |
337 | | 'search' |
| |
338 | | 'view' |
| |
339 | | 'preload' |
| |
340 | | 'highlight' |
| |
341 | | 'history' |
| 351 | const activeHelpSection = ref<HelpSection | null>(null) |
342 | const activeHelpSection = ref<HelpSection | null>(null) |
| 352 | const helpPopupEl = ref<HTMLDivElement>() |
343 | const helpPopupEl = ref<HTMLDivElement>() |
| 353 | const helpPopupPos = ref({ top: -9999, left: -9999 }) |
344 | const helpPopupPos = ref({ top: -9999, left: -9999 }) |
| @@ -651,8 +642,6 @@ const pageMeta = (() => { |
| 651 | return map |
642 | return map |
| 652 | })() |
643 | })() |
| 653 | |
644 | |
| 654 | type SearchMode = 'exact' | 'fuzzy' | 'url' |
| |
| 655 | |
| |
| 656 | interface TextSearchWorkerPayload { |
645 | interface TextSearchWorkerPayload { |
| 657 | results: (SearchResult & Result)[] |
646 | results: (SearchResult & Result)[] |
| 658 | terms: string[] |
647 | terms: string[] |
| @@ -674,7 +663,7 @@ interface LoadIndexWorkerRequest { |
| 674 | interface TextSearchWorkerRequest { |
663 | interface TextSearchWorkerRequest { |
| 675 | type: 'text-search' |
664 | type: 'text-search' |
| 676 | query: string |
665 | query: string |
| 677 | mode: SearchMode |
666 | mode: SearchSortMode |
| 678 | pageOrderEntries: [string, number][] |
667 | pageOrderEntries: [string, number][] |
| 679 | } |
668 | } |
| 680 | |
669 | |
| @@ -1797,9 +1786,11 @@ function getSearchResultHref(item: SearchResult & Result) { |
| 1797 | } |
1786 | } |
| 1798 | |
1787 | |
| 1799 | function navigateToUrlResult(item: UrlResult) { |
1788 | function navigateToUrlResult(item: UrlResult) { |
| 1800 | saveToHistory(filterText.value, searchMode.value, [getPageLabel(item.pageId), ...item.titles, item.linkText].map(toHistoryPathHtml).filter(Boolean), buildResultHref(item.pageId, item.tabs, item.anchor)) |
1789 | saveToHistory(filterText.value, searchMode.value, [getPageLabel(item.pageId), ...item.titles, item.linkText].map(toHistoryPathHtml).filter(Boolean), buildResultHref(item.pageId, item.tabs, item.anchor), item.linkText) |
| 1801 | window.dispatchEvent( |
1790 | window.dispatchEvent( |
| 1802 | new CustomEvent('search-nav', { detail: { query: filterText.value } }) |
1791 | new CustomEvent('search-nav', { |
| |
1792 | detail: { query: filterText.value, resultText: item.linkText } |
| |
1793 | }) |
| 1803 | ) |
1794 | ) |
| 1804 | router.go(buildResultHref(item.pageId, item.tabs, item.anchor)) |
1795 | router.go(buildResultHref(item.pageId, item.tabs, item.anchor)) |
| 1805 | showSearch.value = false |
1796 | showSearch.value = false |
| @@ -1837,10 +1828,10 @@ onKeyStroke('Enter', (e) => { |
| 1837 | } |
1828 | } |
| 1838 | |
1829 | |
| 1839 | if (selectedPackage) { |
1830 | if (selectedPackage) { |
| 1840 | saveToHistory(filterText.value, searchMode.value, [getPageLabel(getPageKey(String(selectedPackage.id))), ...selectedPackage.titles, selectedPackage.title].map(toHistoryPathHtml).filter(Boolean), getSearchResultHref(selectedPackage)) |
1831 | saveToHistory(filterText.value, searchMode.value, [getPageLabel(getPageKey(String(selectedPackage.id))), ...selectedPackage.titles, selectedPackage.title].map(toHistoryPathHtml).filter(Boolean), getSearchResultHref(selectedPackage), selectedPackage.title) |
| 1841 | window.dispatchEvent( |
1832 | window.dispatchEvent( |
| 1842 | new CustomEvent('search-nav', { |
1833 | new CustomEvent('search-nav', { |
| 1843 | detail: { query: filterText.value } |
1834 | detail: { query: filterText.value, resultText: selectedPackage.title } |
| 1844 | }) |
1835 | }) |
| 1845 | ) |
1836 | ) |
| 1846 | router.go(getSearchResultHref(selectedPackage)) |
1837 | router.go(getSearchResultHref(selectedPackage)) |
| @@ -1849,10 +1840,10 @@ onKeyStroke('Enter', (e) => { |
| 1849 | }) |
1840 | }) |
| 1850 | |
1841 | |
| 1851 | function onResultClick(item: SearchResult & Result) { |
1842 | function onResultClick(item: SearchResult & Result) { |
| 1852 | saveToHistory(filterText.value, searchMode.value, [getPageLabel(getPageKey(String(item.id))), ...item.titles, item.title].map(toHistoryPathHtml).filter(Boolean), getSearchResultHref(item)) |
1843 | saveToHistory(filterText.value, searchMode.value, [getPageLabel(getPageKey(String(item.id))), ...item.titles, item.title].map(toHistoryPathHtml).filter(Boolean), getSearchResultHref(item), item.title) |
| 1853 | window.dispatchEvent( |
1844 | window.dispatchEvent( |
| 1854 | new CustomEvent('search-nav', { |
1845 | new CustomEvent('search-nav', { |
| 1855 | detail: { query: filterText.value } |
1846 | detail: { query: filterText.value, resultText: item.title } |
| 1856 | }) |
1847 | }) |
| 1857 | ) |
1848 | ) |
| 1858 | showSearch.value = false |
1849 | showSearch.value = false |
| @@ -2747,6 +2738,54 @@ function onMouseMove(e: MouseEvent) { |
| 2747 | </button> |
2738 | </button> |
| 2748 | </div> |
2739 | </div> |
| 2749 | </div> |
2740 | </div> |
| |
2741 | <div class="settings-section"> |
| |
2742 | <div class="settings-section-header"> |
| |
2743 | <div class="settings-section-label"> |
| |
2744 | <Highlighter :size="14" stroke-width="1.75" /> |
| |
2745 | Highlight |
| |
2746 | </div> |
| |
2747 | <button |
| |
2748 | type="button" |
| |
2749 | class="settings-help-btn" |
| |
2750 | :class="{ active: activeHelpSection === 'highlight' }" |
| |
2751 | aria-label="Search result highlight help" |
| |
2752 | @click.stop="toggleHelpSection('highlight', $event)" |
| |
2753 | @mouseenter="onHelpEnter('highlight', $event)" |
| |
2754 | @mouseleave="onHelpLeave" |
| |
2755 | > |
| |
2756 | <span class="i-carbon:help-filled settings-help-icon" /> |
| |
2757 | </button> |
| |
2758 | </div> |
| |
2759 | <div |
| |
2760 | class="settings-options" |
| |
2761 | :class="{ 'is-highlighted': activeHelpSection === 'highlight' }" |
| |
2762 | > |
| |
2763 | <button |
| |
2764 | type="button" |
| |
2765 | class="settings-option" |
| |
2766 | :class="{ active: searchResultHighlightMode === 'soft' }" |
| |
2767 | @click="searchResultHighlightMode = 'soft'" |
| |
2768 | > |
| |
2769 | <span>Soft</span> |
| |
2770 | </button> |
| |
2771 | <button |
| |
2772 | type="button" |
| |
2773 | class="settings-option" |
| |
2774 | :class="{ active: searchResultHighlightMode === 'solid' }" |
| |
2775 | @click="searchResultHighlightMode = 'solid'" |
| |
2776 | > |
| |
2777 | <span>Solid</span> |
| |
2778 | </button> |
| |
2779 | <button |
| |
2780 | type="button" |
| |
2781 | class="settings-option" |
| |
2782 | :class="{ active: searchResultHighlightMode === 'off' }" |
| |
2783 | @click="searchResultHighlightMode = 'off'" |
| |
2784 | > |
| |
2785 | <span>Off</span> |
| |
2786 | </button> |
| |
2787 | </div> |
| |
2788 | </div> |
| 2750 | <div class="settings-section"> |
2789 | <div class="settings-section"> |
| 2751 | <div class="settings-section-header"> |
2790 | <div class="settings-section-header"> |
| 2752 | <div class="settings-section-label"> |
2791 | <div class="settings-section-label"> |
| @@ -2870,6 +2909,25 @@ function onMouseMove(e: MouseEvent) { |
| 2870 | </div> |
2909 | </div> |
| 2871 | </div> |
2910 | </div> |
| 2872 | </template> |
2911 | </template> |
| |
2912 | <template v-else-if="activeHelpSection === 'highlight'"> |
| |
2913 | <h4 class="sh-title"> |
| |
2914 | <Highlighter :size="16" stroke-width="1.75" class="sh-title-icon" /> |
| |
2915 | Search Result Highlight |
| |
2916 | </h4> |
| |
2917 | <p class="sh-desc"> |
| |
2918 | Highlights the exact result you open. |
| |
2919 | </p> |
| |
2920 | <div class="sh-options"> |
| |
2921 | <div class="sh-option"> |
| |
2922 | <strong>Soft</strong> |
| |
2923 | <span>Soft accent background with a solid border.</span> |
| |
2924 | </div> |
| |
2925 | <div class="sh-option"> |
| |
2926 | <strong>Solid</strong> |
| |
2927 | <span>Solid accent fill with no border.</span> |
| |
2928 | </div> |
| |
2929 | </div> |
| |
2930 | </template> |
| 2873 | <template v-else-if="activeHelpSection === 'history'"> |
2931 | <template v-else-if="activeHelpSection === 'history'"> |
| 2874 | <h4 class="sh-title"> |
2932 | <h4 class="sh-title"> |
| 2875 | <Clock :size="16" stroke-width="1.75" class="sh-title-icon" /> |
2933 | <Clock :size="16" stroke-width="1.75" class="sh-title-icon" /> |
| @@ -3974,4 +4032,4 @@ html.effects-disabled .clear-button:active { |
| 3974 | color: var(--vp-c-text-1); |
4032 | color: var(--vp-c-text-1); |
| 3975 | opacity: 1; |
4033 | opacity: 1; |
| 3976 | } |
4034 | } |
| 3977 | </style> |
4035 | </style>\ No newline at end of file |