🐛 fix(vscode): 代码阅读按 ⌘↓ 跳高亮不再来回闪,筛选栏加上上一处、下一处

This commit is contained in:
cruldra committed 2026-10-03 03:11:46 +08:00
1 parent 70a53e5a68
commit b16cc6409e
8 files changed
+221 -36

No files matched your search

@@ -6,7 +6,7 @@ import { createPythonAdapter } from '../../../src/codeReader/languages/python'
import { WASM_DIR, withBlocks } from '../../../src/codeReader/testSupport'
import { pythonZhTranslator } from '../../../src/codeReader/translators/pythonZh'
import { DefinitionLinks } from './definitionLinks'
import { clickAction, isCurrent, KEY_SCROLL_MS, KEY_TO_COMMAND_MS, KeyScroll, occurrenceCount, OccurrenceHighlight, OccurrenceNavigation, occurrenceStyle, segmentOccurrence, sourceOf, stepIndex } from './occurrences'
import { clickAction, isCurrent, KEY_SCROLL_MS, KEY_TO_COMMAND_MS, KeyScroll, occurrenceCount, OccurrenceHighlight, occurrenceJumpKey, OccurrenceNavigation, occurrenceStyle, segmentOccurrence, sourceOf, stepIndex } from './occurrences'
function name(text: string, offset: number): Segment {
return { text, role: 'variable', offset }
@@ -359,4 +359,34 @@ describe('occurrences:用键盘在各处出现之间跳', () => {
scroll.forget()
expect(scroll.scrolled({ x: 0, y: 300 }, 1130)).toBeUndefined()
})
it('我们自己滚过的位置不算浏览器滚走:差 1 像素、滚进视口都不再拉一次,真被滚走仍拉回', () => {
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({ x: 0, y: 39 }, 1020)).toBeUndefined()
expect(scroll.scrolled({ x: 0, y: 39 }, 1021)).toBeUndefined()
expect(scroll.scrolled({ x: 0, y: 800 }, 1022)).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 })
})
it('默认快捷键:mac 是 ⌘↓ / ⌘↑,别的系统是 ctrl;带了别的修饰键不算', () => {
const key = (name: string, mod: Partial<{ metaKey: boolean, ctrlKey: boolean, altKey: boolean, shiftKey: boolean }> = {}) =>
({ key: name, metaKey: false, ctrlKey: false, altKey: false, shiftKey: false, ...mod })
expect(occurrenceJumpKey(key('ArrowDown', { metaKey: true }), true)).toBe(true)
expect(occurrenceJumpKey(key('ArrowUp', { metaKey: true }), true)).toBe(true)
expect(occurrenceJumpKey(key('ArrowDown', { ctrlKey: true }), true)).toBe(false)
expect(occurrenceJumpKey(key('ArrowDown', { ctrlKey: true }), false)).toBe(true)
expect(occurrenceJumpKey(key('ArrowUp', { ctrlKey: true }), false)).toBe(true)
expect(occurrenceJumpKey(key('ArrowDown', { metaKey: true }), false)).toBe(false)
expect(occurrenceJumpKey(key('ArrowDown', { metaKey: true, shiftKey: true }), true)).toBe(false)
expect(occurrenceJumpKey(key('ArrowDown', { metaKey: true, altKey: true }), true)).toBe(false)
expect(occurrenceJumpKey(key('ArrowLeft', { metaKey: true }), true)).toBe(false)
})
})