🐛 fix(vscode): 跳到定义时对准名字并闪

This commit is contained in:
cruldra committed 2026-10-03 03:22:20 +08:00
1 parent 06df8919c8
commit fc403d5b20
6 files changed
+307 -50

No files matched your search

@@ -148,8 +148,20 @@ describe('跳到定义:滚到哪块、展开哪些', () => {
it('页面上没有这个名字:按行找包含它的块,也展开祖先', () => {
expect(revealPlan(BLOCKS, 3, 999)).toEqual({ id: '1.0', expand: ['1'] })
expect(revealPlan(BLOCKS, 6, 999)).toEqual({ id: '1.0.0', expand: ['1', '1.0'] })
expect(revealPlan(BLOCKS, 20, 999)).toEqual({ id: '2', expand: [] })
expect(revealPlan(BLOCKS, 4, 999)).toEqual({ id: '1.0.0', expand: ['1', '1.0'] })
expect(revealPlan(BLOCKS, 8, 999)).toEqual({ id: '2', expand: [] })
})
it('一行落在后一块,不选已经结束的前一块;都包住时取最小的那块', () => {
const blocks = [
{ ...textBlock('0', 'class', 3, [word('类')]), endLine: 4 },
{ ...textBlock('1', 'function', 1, [word('函数')]), endLine: 8 },
]
expect(revealPlan(blocks, 6, 999)).toEqual({ id: '1', expand: [] })
const inner = textBlock('0.0', 'return', 2, [word('返回')])
const outer = { ...textBlock('0', 'function', 1, [word('函数')], [inner]), endLine: 8 }
expect(revealPlan([outer], 2, 999)).toEqual({ id: '0.0', expand: ['0'] })
expect(revealPlan([outer], 6, 999)).toEqual({ id: '0', expand: [] })
})
it('函数块默认折叠:目标在函数体里时,要展开的块里有这个函数;展开过一次就记住,不再挡着', () => {
@@ -170,7 +182,7 @@ describe('跳到定义:滚到哪块、展开哪些', () => {
expect(revealPlan([card], 0, 300)).toEqual({ id: '0.1.0', expand: [propertyRowId('0', 3), '0.1', propertyRowId('0.1', 2)] })
})
it('按行找:同一行有几块取外层那块;行在所有块之前取第一块;没有块时没有目标', () => {
it('按行找:同一行有几块、一样大时取外层那块;行在所有块之前取第一块;没有块时没有目标', () => {
const sameLine = [textBlock('0', 'if', 1, [word('如果')], [textBlock('0.0', 'return', 1, [word('返回')])])]
expect(revealPlan(sameLine, 1, 999)).toEqual({ id: '0', expand: [] })
expect(revealPlan(sameLine, 0, 999)).toEqual({ id: '0', expand: [] })
@@ -198,6 +210,16 @@ describe('跳到定义:闪哪一处(defines)', () => {
]),
]
it('父块的大范围盖住定义下标时,停在后面那个显示着这个名字的函数上,不闪父块', () => {
const parent = {
...factBlock('0', 'class', 1, [{ label: '名称', value: [name('DeployActionError', 10)] }]),
endLine: 12,
defines: range(0, 400),
}
const fn = factBlock('1', 'function', 14, [{ label: '名称', value: [name('fetchAppDeployments', 80)] }])
expect(revealPlan([parent, fn], 14, 80)).toEqual({ id: '1', expand: [] })
})
it('定义是块自己的名字:闪整块,属性行也标了它也一样', () => {
expect(revealPlan(blocks, 0, 4)).toEqual({ id: '0', expand: [] })
})
@@ -451,4 +473,8 @@ describe('把目标块滚进视口', () => {
expect(scrollTopToShow({ top: 580, bottom: 620 }, 100, 500)).toBe(350)
expect(scrollTopToShow({ top: 900, bottom: 1600 }, 0, 500)).toBe(900)
})
it('筛选栏挡住时,滚动位置让目标出现在筛选栏下面', () => {
expect(scrollTopToShow({ top: 900, bottom: 1600 }, 0, 548, 48)).toBe(852)
})
})