✨ feat(vscode): 代码阅读预览顶部加块筛选栏
语言插件按和语言无关的 id 报块属性(通用的由宿主从 facts 推),翻译插件起名,webview 只按 id 筛; 筛选整个工作区共用、记在 workspaceState;JavaScript 不再显示「抽象:否」「仅类型:否」
This commit is contained in:
1 parent
4eaf2ae11d
commit
1c7e31c51a
29 files changed
+1364
-319
No files matched your search
@@ -7,7 +7,12 @@ import { postMessage, viewState } from './vscode'
|
||||
/** 滚动时最多这么久记一次位置 */
|
||||
const RECORD_INTERVAL_MS = 100
|
||||
|
||||
/** 页面上每块(BlockCard 带 data-line)的位置,按页面上的先后。 */
|
||||
/** 顶部钉住的筛选栏的高度:视口里露出块的部分从它下面开始,记位置、滚过去都按这部分算。 */
|
||||
export function pinnedHeight(): number {
|
||||
return document.querySelector<HTMLElement>('.cr-filter-bar')?.offsetHeight ?? 0
|
||||
}
|
||||
|
||||
/** 页面上每块(BlockCard 带 data-line)的位置,按页面上的先后;被筛掉的块不在页面上,不算。 */
|
||||
export function measureBlocks(): BlockBox[] {
|
||||
const y = window.scrollY
|
||||
return Array.from(document.querySelectorAll<HTMLElement>('.cr-block[data-line]'), (el) => {
|
||||
@@ -18,7 +23,7 @@ export function measureBlocks(): BlockBox[] {
|
||||
|
||||
/** 记下视口顶部那块;它的起始行变了才报给扩展端。 */
|
||||
function record(reportedLine: { current: number | undefined }): void {
|
||||
const anchor = anchorAt(measureBlocks(), window.scrollY)
|
||||
const anchor = anchorAt(measureBlocks(), window.scrollY + pinnedHeight())
|
||||
if (!anchor)
|
||||
return
|
||||
viewState.update({ scroll: anchor })
|
||||
@@ -46,7 +51,7 @@ export function useScrollPosition(doc: DocumentMessage | null): void {
|
||||
const saved = viewState.get().scroll
|
||||
const top = doc.reveal === undefined && saved ? scrollTopFor(measureBlocks(), saved) : undefined
|
||||
if (top !== undefined)
|
||||
window.scrollTo(0, top)
|
||||
window.scrollTo(0, top - pinnedHeight())
|
||||
record(reportedLine)
|
||||
}, [doc])
|
||||
|
||||
|
||||
Reference in new issue
Block a user