⚡ perf(vscode): 代码阅读预览的卡片位置量过就记着,内容或大小变了才重量:粘性标题、记滚动位置、上报可见行、跳转按顶层块二分找,滚动时不再每帧量全部卡片,滚动回调里也不读会逼排版的位置
This commit is contained in:
1 parent
b2e998665e
commit
ffb0f147e1
13 files changed
+380
-102
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import type { Click, Highlight } from './occurrences'
|
||||
import type { BlockView, Inline, Occurrence, PreviewText, PropertyItem, Segment, WebviewToExtension } from './types'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { toBlockViews } from '../../../src/codeReader/blockView'
|
||||
import { createPythonAdapter } from '../../../src/codeReader/languages/python'
|
||||
import { WASM_DIR, withBlocks } from '../../../src/codeReader/testSupport'
|
||||
@@ -359,26 +359,38 @@ describe('occurrences:用键盘在各处出现之间跳', () => {
|
||||
scroll.press({ x: 0, y: 40 }, 1000)
|
||||
scroll.take(1012)
|
||||
// 刚回到按键那一刻、还没跳完:守住按键那一刻的位置
|
||||
expect(scroll.scrolled({ x: 0, y: 300 }, 1020)).toEqual({ x: 0, y: 40 })
|
||||
expect(scroll.scrolled(1020, () => ({ x: 0, y: 300 }))).toEqual({ x: 0, y: 40 })
|
||||
scroll.hold({ x: 0, y: 900 })
|
||||
expect(scroll.scrolled({ x: 0, y: 900 }, 1030)).toBeUndefined()
|
||||
expect(scroll.scrolled({ x: 0, y: 1200 }, 1040)).toEqual({ x: 0, y: 900 })
|
||||
expect(scroll.scrolled({ x: 0, y: 1200 }, 1000 + KEY_SCROLL_MS + 1)).toBeUndefined()
|
||||
expect(scroll.scrolled({ x: 0, y: 1300 }, 1000 + KEY_SCROLL_MS + 2)).toBeUndefined()
|
||||
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()
|
||||
})
|
||||
|
||||
it('不是按键触发的跳转、又按了键、点了鼠标:不守', () => {
|
||||
const scroll = new KeyScroll()
|
||||
scroll.take(10)
|
||||
scroll.hold({ x: 0, y: 900 })
|
||||
expect(scroll.scrolled({ x: 0, y: 0 }, 20)).toBeUndefined()
|
||||
expect(scroll.scrolled(20, () => ({ x: 0, y: 0 }))).toBeUndefined()
|
||||
scroll.press({ x: 0, y: 40 }, 1000)
|
||||
scroll.take(1010)
|
||||
scroll.press({ x: 0, y: 40 }, 1100)
|
||||
expect(scroll.scrolled({ x: 0, y: 300 }, 1110)).toBeUndefined()
|
||||
expect(scroll.scrolled(1110, () => ({ x: 0, y: 300 }))).toBeUndefined()
|
||||
scroll.take(1120)
|
||||
scroll.forget()
|
||||
expect(scroll.scrolled({ x: 0, y: 300 }, 1130)).toBeUndefined()
|
||||
expect(scroll.scrolled(1130, () => ({ x: 0, y: 300 }))).toBeUndefined()
|
||||
})
|
||||
|
||||
it('不守着时滚动不读滚动位置(读它会逼浏览器先排版)', () => {
|
||||
const scroll = new KeyScroll()
|
||||
const read = vi.fn(() => ({ x: 0, y: 300 }))
|
||||
expect(scroll.scrolled(10, read)).toBeUndefined()
|
||||
scroll.press({ x: 0, y: 40 }, 1000)
|
||||
expect(scroll.scrolled(1005, read)).toBeUndefined()
|
||||
expect(read).not.toHaveBeenCalled()
|
||||
scroll.take(1010)
|
||||
expect(scroll.scrolled(1020, read)).toEqual({ x: 0, y: 40 })
|
||||
expect(read).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('我们自己滚过的位置不算浏览器滚走:差 1 像素、滚进视口都不再拉一次,真被滚走仍拉回', () => {
|
||||
@@ -389,12 +401,12 @@ describe('occurrences:用键盘在各处出现之间跳', () => {
|
||||
scroll.own({ x: 0, y: 39 })
|
||||
scroll.own({ x: 0, y: 40 })
|
||||
scroll.own({ x: 0, y: 800 })
|
||||
expect(scroll.scrolled({ x: 0, y: 39 }, 1020)).toBeUndefined()
|
||||
expect(scroll.scrolled({ x: 0, y: 39 }, 1021)).toBeUndefined()
|
||||
expect(scroll.scrolled({ x: 0, y: 800 }, 1022)).toBeUndefined()
|
||||
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()
|
||||
scroll.hold({ x: 0, y: 800 })
|
||||
expect(scroll.scrolled({ x: 0, y: 39 }, 1030)).toBeUndefined()
|
||||
expect(scroll.scrolled({ x: 0, y: 300 }, 1040)).toEqual({ 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 })
|
||||
})
|
||||
|
||||
it('默认快捷键:mac 是 ⌘↓ / ⌘↑,别的系统是 ctrl;带了别的修饰键不算', () => {
|
||||
|
||||
Reference in new issue
Block a user