🐛 fix(vscode): 代码阅读预览跳到定义后页面还在长高(注释里的 mermaid 画成图、中文名到了)不再把视口带跑:页面滚动统一交给滚动所有者,跟住跳到的目标、用户自己滚了改钉视口顶部那块,关掉浏览器自带的滚动锚定

This commit is contained in:
cruldra committed 2026-10-14 06:11:25 +11:00
1 parent 2fa6319dd4
commit 3c5f5f5f35
24 files changed
+1016 -149

No files matched your search

@@ -1,6 +1,6 @@
import type { BlockBox } from './scrollPosition'
import { describe, expect, it } from 'vitest'
import { anchorAt, blockForLine, scrollTopFor } from './scrollPosition'
import { anchorAt, blockForLine, holdAt, scrollTopFor } from './scrollPosition'
// 页面上的块:顶部有 20px 工具栏,块与块之间 8px 间距
const boxes: BlockBox[] = [
@@ -32,6 +32,27 @@ describe('anchorAt:视口顶部那块', () => {
})
})
describe('holdAt:页面变了也钉住不动的那块', () => {
it('视口顶部落在块中间:钉这块', () => {
expect(holdAt(boxes, 150)).toEqual({ line: 4, offset: 34, scrollTop: 150 })
})
it('视口顶部落在块间空隙(或上面那块的问答区)里:钉上面那块,下面那块长高不牵动视口', () => {
expect(holdAt(boxes, 110)).toEqual({ line: 3, offset: 42, scrollTop: 110 })
})
it('还在所有块上面:不钉', () => {
expect(holdAt(boxes, 0)).toBeUndefined()
})
it('起始行相同的外层块和第一个子块:钉靠前的那块,按起始行找回来还是原处', () => {
const nested = [{ line: 0, top: 20, bottom: 60 }, { line: 4, top: 68, bottom: 100 }, { line: 4, top: 108, bottom: 200 }]
const anchor = holdAt(nested, 150)!
expect(anchor).toEqual({ line: 4, offset: 82, scrollTop: 150 })
expect(scrollTopFor(nested, anchor)).toBe(150)
})
})
describe('scrollTopFor:按记下的位置恢复', () => {
it('内容没变:回到原来的 scrollTop', () => {
expect(scrollTopFor(boxes, anchorAt(boxes, 150)!)).toBe(150)