Commit 5323e69350
Unsigned
Layout: unified · split
docs/.vitepress/theme/components/Search.vue +20 −9
| @@ -973,19 +973,34 @@ async function buildVisibleExcerpts() { | |||
| 973 | if (!showDetailedList.value || urlSearchMode.value) return | 973 | if (!showDetailedList.value || urlSearchMode.value) return |
| 974 | 974 | ||
| 975 | let builtAny = false | 975 | let builtAny = false |
| 976 | const buildAll = async (docIds: string[]) => { | 976 | let sliceStart = performance.now() |
| 977 | |||
| 978 | const refreshRows = async () => { | ||
| 979 | const keepSelected = selectedIndex.value | ||
| 980 | results.value = toRows(results.value) | ||
| 981 | await nextTick() | ||
| 982 | if (token !== excerptBuildToken) return false | ||
| 983 | selectedIndex.value = keepSelected | ||
| 984 | return true | ||
| 985 | } | ||
| 986 | |||
| 987 | const buildAll = async (docIds: string[], progressive = false) => { | ||
| 977 | for (const docId of docIds) { | 988 | for (const docId of docIds) { |
| 978 | if (cache.get(docId)) continue | 989 | if (cache.get(docId)) continue |
| 979 | await buildDocExcerpt(docId) | 990 | await buildDocExcerpt(docId) |
| 980 | if (token !== excerptBuildToken) return false | 991 | if (token !== excerptBuildToken) return false |
| 981 | builtAny = true | 992 | builtAny = true |
| 982 | await nextFrame() | 993 | if (performance.now() - sliceStart > 40) { |
| 983 | if (token !== excerptBuildToken) return false | 994 | if (progressive && !(await refreshRows())) return false |
| 995 | await nextFrame() | ||
| 996 | if (token !== excerptBuildToken) return false | ||
| 997 | sliceStart = performance.now() | ||
| 998 | } | ||
| 984 | } | 999 | } |
| 985 | return true | 1000 | return true |
| 986 | } | 1001 | } |
| 987 | 1002 | ||
| 988 | if (!(await buildAll(visiblePageDocs(0)))) return | 1003 | if (!(await buildAll(visiblePageDocs(0), true))) return |
| 989 | 1004 | ||
| 990 | const rowsStale = pagedResults.value.some((r) => { | 1005 | const rowsStale = pagedResults.value.some((r) => { |
| 991 | if (r.text) return false | 1006 | if (r.text) return false |
| @@ -994,11 +1009,7 @@ async function buildVisibleExcerpts() { | |||
| 994 | }) | 1009 | }) |
| 995 | 1010 | ||
| 996 | if (builtAny || rowsStale) { | 1011 | if (builtAny || rowsStale) { |
| 997 | const keepSelected = selectedIndex.value | 1012 | if (!(await refreshRows())) return |
| 998 | results.value = toRows(results.value) | ||
| 999 | await nextTick() | ||
| 1000 | if (token !== excerptBuildToken) return | ||
| 1001 | selectedIndex.value = keepSelected | ||
| 1002 | await reapplyHighlights() | 1013 | await reapplyHighlights() |
| 1003 | if (token !== excerptBuildToken) return | 1014 | if (token !== excerptBuildToken) return |
| 1004 | } | 1015 | } |