🐛 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

@@ -369,54 +369,49 @@ describe('occurrences:用键盘在各处出现之间跳', () => {
scroll.press({ x: 0, y: 40 }, 1000)
scroll.take(1012)
// 刚回到按键那一刻、还没跳完:守住按键那一刻的位置
expect(scroll.scrolled(1020, () => ({ x: 0, y: 300 }))).toEqual({ x: 0, y: 40 })
expect(scroll.scrolled(1020, () => ({ x: 0, y: 300 }), false)).toEqual({ x: 0, y: 40 })
scroll.hold({ x: 0, y: 900 })
expect(scroll.scrolled(1030, () => ({ x: 0, y: 900 }))).toBeUndefined()
expect(scroll.scrolled(1040, () => ({ x: 0, y: 1200 }))).toEqual({ x: 0, y: 900 })
expect(scroll.scrolled(1000 + KEY_SCROLL_MS + 1, () => ({ x: 0, y: 1200 }))).toBeUndefined()
expect(scroll.scrolled(1000 + KEY_SCROLL_MS + 2, () => ({ x: 0, y: 1300 }))).toBeUndefined()
expect(scroll.scrolled(1030, () => ({ x: 0, y: 900 }), false)).toBeUndefined()
expect(scroll.scrolled(1040, () => ({ x: 0, y: 1200 }), false)).toEqual({ x: 0, y: 900 })
expect(scroll.scrolled(1000 + KEY_SCROLL_MS + 1, () => ({ x: 0, y: 1200 }), false)).toBeUndefined()
expect(scroll.scrolled(1000 + KEY_SCROLL_MS + 2, () => ({ x: 0, y: 1300 }), false)).toBeUndefined()
})
it('不是按键触发的跳转、又按了键、点了鼠标:不守', () => {
const scroll = new KeyScroll()
scroll.take(10)
scroll.hold({ x: 0, y: 900 })
expect(scroll.scrolled(20, () => ({ x: 0, y: 0 }))).toBeUndefined()
expect(scroll.scrolled(20, () => ({ x: 0, y: 0 }), false)).toBeUndefined()
scroll.press({ x: 0, y: 40 }, 1000)
scroll.take(1010)
scroll.press({ x: 0, y: 40 }, 1100)
expect(scroll.scrolled(1110, () => ({ x: 0, y: 300 }))).toBeUndefined()
expect(scroll.scrolled(1110, () => ({ x: 0, y: 300 }), false)).toBeUndefined()
scroll.take(1120)
scroll.forget()
expect(scroll.scrolled(1130, () => ({ x: 0, y: 300 }))).toBeUndefined()
expect(scroll.scrolled(1130, () => ({ x: 0, y: 300 }), false)).toBeUndefined()
})
it('不守着时滚动不读滚动位置(读它会逼浏览器先排版)', () => {
const scroll = new KeyScroll()
const read = vi.fn(() => ({ x: 0, y: 300 }))
expect(scroll.scrolled(10, read)).toBeUndefined()
expect(scroll.scrolled(10, read, false)).toBeUndefined()
scroll.press({ x: 0, y: 40 }, 1000)
expect(scroll.scrolled(1005, read)).toBeUndefined()
expect(scroll.scrolled(1005, read, false)).toBeUndefined()
expect(read).not.toHaveBeenCalled()
scroll.take(1010)
expect(scroll.scrolled(1020, read)).toEqual({ x: 0, y: 40 })
expect(scroll.scrolled(1020, read, false)).toEqual({ x: 0, y: 40 })
expect(read).toHaveBeenCalledTimes(1)
})
it('我们自己滚过的位置不算浏览器滚走:差 1 像素、滚进视口都不再拉一次,真被滚走仍拉回', () => {
it('我们自己滚的(滚动所有者认出来的)不算浏览器滚走,改守滚到的位置;之后真被滚走拉回到那里', () => {
const scroll = new KeyScroll()
scroll.press({ x: 0, y: 40 }, 1000)
scroll.take(1012)
// scrollBack 先滚到 39 再回到 40;滚进视口则落到另一个位置。这些事件可能晚于滚动调用才到
scroll.own({ x: 0, y: 39 })
scroll.own({ x: 0, y: 40 })
scroll.own({ x: 0, y: 800 })
expect(scroll.scrolled(1020, () => ({ x: 0, y: 39 }))).toBeUndefined()
expect(scroll.scrolled(1021, () => ({ x: 0, y: 39 }))).toBeUndefined()
expect(scroll.scrolled(1022, () => ({ x: 0, y: 800 }))).toBeUndefined()
// 滚进视口落到 800,跳完守它;页面长高时滚动所有者自己滚到 1320
expect(scroll.scrolled(1020, () => ({ x: 0, y: 800 }), true)).toBeUndefined()
scroll.hold({ x: 0, y: 800 })
expect(scroll.scrolled(1030, () => ({ x: 0, y: 39 }))).toBeUndefined()
expect(scroll.scrolled(1040, () => ({ x: 0, y: 300 }))).toEqual({ x: 0, y: 800 })
expect(scroll.scrolled(1030, () => ({ x: 0, y: 1320 }), true)).toBeUndefined()
expect(scroll.scrolled(1040, () => ({ x: 0, y: 300 }), false)).toEqual({ x: 0, y: 1320 })
})
it('默认快捷键:mac 是 ⌘↓ / ⌘↑,别的系统是 ctrl;带了别的修饰键不算', () => {