⚡ 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,10 +2,11 @@ import type { ReactElement, RefObject } from 'react'
import type { BlockView, StickyScrollSettings } from './types'
import { useContext, useLayoutEffect, useMemo } from 'react'
import { KindIcon } from './kindIcons'
import { pageLayout } from './pageLayout'
import { SegmentText, TextMarksContext } from './SegmentText'
import { selectStore } from './store'
import { flash } from './useReveal'
import { pinnedHeight, usePinnedHeight } from './useScrollPosition'
import { usePinnedHeight } from './useScrollPosition'
import { STICKY_LINE_HEIGHT, stickyInset, useStickyLines } from './useStickyScroll'
/** 块 id → 块,连同各层子块 */
@@ -74,7 +75,7 @@ export function StickyLines({ content, blocks, settings }: { content: RefObject<
const card = content.current?.querySelector<HTMLElement>(`.cr-block[data-id="${id}"]`)
if (!card)
return
window.scrollTo(0, card.getBoundingClientRect().top + window.scrollY - pinnedHeight() - stickyInset(card, settings))
window.scrollTo(0, card.getBoundingClientRect().top + window.scrollY - pageLayout.pinnedHeight() - stickyInset(card, settings))
flash(card)
}