⚡ perf(vscode): 代码阅读预览的卡片位置量过就记着,内容或大小变了才重量:粘性标题、记滚动位置、上报可见行、跳转按顶层块二分找,滚动时不再每帧量全部卡片,滚动回调里也不读会逼排版的位置

This commit is contained in:
cruldra committed 2026-10-13 14:58:03 +11:00
1 parent b2e998665e
commit ffb0f147e1
13 files changed
+380 -102

No files matched your search

@@ -2,9 +2,8 @@ import type { ScrollPosition } from './occurrences'
import type { DocumentMessage, Reveal } from './types'
import { useLayoutEffect } from 'react'
import { blockPath } from './filter'
import { pageLayout } from './pageLayout'
import { revealPlan, scrollTopToShow, uncoveredPlan } from './reveal'
import { blockForLine } from './scrollPosition'
import { measureBlocks, pinnedHeight } from './useScrollPosition'
import { stickyHeight } from './useStickyScroll'
/** 让一块或属性表里的一行闪几下(codeReader.css 的 [data-flash]);正在闪的同一处再跳一次时从头闪。 */
@@ -28,7 +27,7 @@ export function flash(el: HTMLElement): void {
/** 把 el 滚进钉住的筛选栏和卡片下面的视口。已经整个看得见就不滚。beforeScroll 在真正滚动前拿到将要落到的位置。 */
export function showInViewport(el: HTMLElement, beforeScroll?: (position: ScrollPosition) => void): void {
const rect = el.getBoundingClientRect()
const pinned = pinnedHeight() + stickyHeight()
const pinned = pageLayout.pinnedHeight() + stickyHeight()
const top = scrollTopToShow(
{ top: rect.top + window.scrollY, bottom: rect.bottom + window.scrollY },
window.scrollY,
@@ -75,9 +74,9 @@ export function useReveal(
if (!doc || !reveal)
return
if (reveal.definition === undefined) {
const top = blockForLine(measureBlocks(), reveal.line)?.top
const top = pageLayout.cardForLine(reveal.line)?.top
if (top !== undefined)
window.scrollTo(0, top - pinnedHeight())
window.scrollTo(0, top - pageLayout.pinnedHeight())
done()
return
}