✨ feat(vscode): 代码阅读库规则卡片不再吞掉字段中间的方法,编辑时收起子块

This commit is contained in:
cruldra committed 2026-09-26 19:58:43 +08:00
1 parent c803fd457f
commit 2251e67ef8
15 files changed
+280 -54

No files matched your search

@@ -1,7 +1,7 @@
import type { DocumentMessage, Reveal } from './types'
import { useLayoutEffect } from 'react'
import { blockPath } from './filter'
import { revealPlan, scrollTopToShow } from './reveal'
import { revealPlan, scrollTopToShow, uncoveredPlan } from './reveal'
import { blockForLine } from './scrollPosition'
import { measureBlocks, pinnedHeight } from './useScrollPosition'
@@ -28,12 +28,14 @@ function flash(el: HTMLElement): void {
* ① 从文本编辑器切过来(没有 definition):包含那一行的块顶到视口顶部(筛选栏下面),折叠着的、被筛掉的不展开;
* ② 跳到定义:目标或它的祖先块被筛掉了,先临时露出这条路径(show);再展开把目标折叠住的块、属性行和子行(expand)——
* 每一步之后重新渲染、再进来一次;最后把目标(整块,或就是这处定义的属性行 / 子行)滚进视口、闪几下。
* 目标被正在编辑的祖先盖住时闪那个祖先(uncoveredPlan)。
*/
export function useReveal(
doc: DocumentMessage | null,
reveal: Reveal | null,
collapsed: ReadonlySet<string>,
filtered: ReadonlySet<string>,
covered: ReadonlyMap<string, string>,
show: (ids: string[]) => void,
expand: (ids: string[]) => void,
done: () => void,
@@ -48,7 +50,8 @@ export function useReveal(
done()
return
}
const plan = revealPlan(doc.blocks, reveal.line, reveal.definition)
const found = revealPlan(doc.blocks, reveal.line, reveal.definition)
const plan = found && uncoveredPlan(found, covered)
const path = plan ? blockPath(plan.id) : []
if (path.some(id => filtered.has(id))) {
show(path)
@@ -71,5 +74,5 @@ export function useReveal(
flash(el)
}
done()
}, [doc, reveal, collapsed, filtered, show, expand, done])
}, [doc, reveal, collapsed, filtered, covered, show, expand, done])
}