✨ feat(vscode): 代码阅读的名字高亮更显眼(当前那处描框、别处画细线),⌘↓ / ⌘↑ 在各处之间跳,跳到折叠处自动展开,筛选栏写第几处
This commit is contained in:
1 parent
c5c5d2b517
commit
49f253b80f
18 files changed
+731
-53
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import type { BlockView, PreviewText, PropertyItem, SourceRange } from './types'
|
||||
import type { BlockView, Occurrence, PreviewText, PropertyItem, SourceRange } from './types'
|
||||
import { blockPath } from './filter'
|
||||
import { showsOccurrence } from './occurrences'
|
||||
import { showsOffset } from './segments'
|
||||
import { propertyItemId, propertyRowId } from './viewState'
|
||||
|
||||
@@ -61,7 +62,7 @@ function locate(block: BlockView, offset: number): Spot | undefined {
|
||||
for (const { row, id } of rows) {
|
||||
if (shows(row.value, offset))
|
||||
return { expand: [] }
|
||||
const expand = showingItem(row.items, id, offset)
|
||||
const expand = showingItem(row.items, id, cell => shows(cell, offset))
|
||||
if (expand)
|
||||
return { expand }
|
||||
}
|
||||
@@ -81,12 +82,12 @@ function definingItem(items: PropertyItem[] | undefined, parentId: string, offse
|
||||
return undefined
|
||||
}
|
||||
|
||||
/** parentId 下面一层层的子行里,哪个显示着 offset 处的名字:要展开的各层(parentId 到那个子行所在的那一层)。 */
|
||||
function showingItem(items: PropertyItem[] | undefined, parentId: string, offset: number): string[] | undefined {
|
||||
/** parentId 下面一层层的子行里,哪个的格子满足 test(显示着要找的名字):要展开的各层(parentId 到那个子行所在的那一层)。 */
|
||||
function showingItem(items: PropertyItem[] | undefined, parentId: string, test: (cell: PreviewText) => boolean): string[] | undefined {
|
||||
for (const [index, item] of (items ?? []).entries()) {
|
||||
if (item.cells.some(cell => shows(cell, offset)))
|
||||
if (item.cells.some(test))
|
||||
return [parentId]
|
||||
const inner = showingItem(item.items, propertyItemId(parentId, index), offset)
|
||||
const inner = showingItem(item.items, propertyItemId(parentId, index), test)
|
||||
if (inner)
|
||||
return [parentId, ...inner]
|
||||
}
|
||||
@@ -119,6 +120,34 @@ export function uncoveredPlan(plan: RevealPlan, covered: ReadonlyMap<string, str
|
||||
return owner === undefined ? plan : { id: owner, expand: blockPath(owner).slice(0, -1) }
|
||||
}
|
||||
|
||||
/** 块里哪儿显示着满足 test 的文字(译文、属性行的值、各层子行的格子):要展开的属性行和子行;不在这块里是 undefined。 */
|
||||
function showingSpot(block: BlockView, test: (text: PreviewText) => boolean): string[] | undefined {
|
||||
if ('translation' in block)
|
||||
return test(block.translation) ? [] : undefined
|
||||
for (const [index, row] of block.properties.entries()) {
|
||||
if (test(row.value))
|
||||
return []
|
||||
const expand = showingItem(row.items, propertyRowId(block.id, index), test)
|
||||
if (expand)
|
||||
return expand
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* 用键盘跳到高亮着的名字的一处出现:页面上按先后第一处显示着它(有段和它重叠)的块,以及要展开的块、属性行和子行。
|
||||
* skip 的块(被筛掉的、正在编辑的、被正在编辑的祖先盖住的)里的不算;Markdown 说明里的名字不带下标,也不算。页面上哪儿都没有时是 undefined。
|
||||
*/
|
||||
export function occurrencePlan(blocks: BlockView[], occurrence: Occurrence, skip: (id: string) => boolean): RevealPlan | undefined {
|
||||
const test = (text: PreviewText): boolean => !('markdown' in text) && showsOccurrence(text, occurrence)
|
||||
for (const { block, ancestors } of placed(blocks)) {
|
||||
const expand = skip(block.id) ? undefined : showingSpot(block, test)
|
||||
if (expand)
|
||||
return { id: block.id, expand: [...ancestors, ...expand] }
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* 让一块露出来时视口顶部要在的位置,和 VS Code 跳到定义一样:整块已经在视口里就不滚;否则放到视口正中,比视口还高就顶部对齐。
|
||||
* viewTop / viewHeight 是视口里露出块的那部分(钉住的筛选栏下面)。
|
||||
|
||||
Reference in new issue
Block a user