⚡ perf(vscode): 代码阅读预览按卡片订阅状态:中文名、调用树棵数、单击高亮、问答一条消息只重画受影响的卡片和文字,新文档里内容没变的块沿用原来的对象不重画,没展开又没说过的块不画问答区

This commit is contained in:
cruldra committed 2026-10-13 14:40:53 +11:00
1 parent 6e2c541558
commit 0ad4748cc6
27 files changed
+1359 -620

No files matched your search

@@ -0,0 +1,41 @@
import { describe, expect, it } from 'vitest'
import { shareUnchanged } from './sharing'
describe('新消息里没变的部分沿用上一份的对象', () => {
const prev = {
version: 1,
blocks: [
{ id: '0', translation: [{ text: 'a', offset: 1 }], children: [] },
{ id: '1', translation: [{ text: 'b', offset: 5 }], children: [{ id: '1.0', children: [] }] },
],
}
it('整份一样:交回上一份本身', () => {
expect(shareUnchanged(prev, structuredClone(prev))).toBe(prev)
})
it('只改了一块:那一块(连同它的各层父对象)是新的,别的块还是原来的对象', () => {
const next = structuredClone(prev)
next.version = 2
next.blocks[1].translation[0].offset = 6
const shared = shareUnchanged(prev, next)
expect(shared).not.toBe(prev)
expect(shared).toEqual(next)
expect(shared.blocks).not.toBe(prev.blocks)
expect(shared.blocks[0]).toBe(prev.blocks[0])
expect(shared.blocks[1]).not.toBe(prev.blocks[1])
expect(shared.blocks[1].children).toBe(prev.blocks[1].children)
})
it('多了、少了项或键都算变了;没有上一份时原样交回', () => {
const longer = { ...structuredClone(prev), blocks: [...structuredClone(prev.blocks), { id: '2', translation: [], children: [] }] }
const shared = shareUnchanged(prev, longer)
expect(shared.blocks).not.toBe(prev.blocks)
expect(shared.blocks[0]).toBe(prev.blocks[0])
const withKey = { ...structuredClone(prev), error: 'x' }
expect(shareUnchanged(prev, withKey)).not.toBe(prev)
const { version: _, ...withoutKey } = structuredClone(prev)
expect(shareUnchanged(prev, withoutKey)).not.toBe(prev)
expect(shareUnchanged(undefined, withKey)).toBe(withKey)
})
})