✨ feat(vscode): 代码阅读入口、文件树与预览编辑器

This commit is contained in:
cruldra committed 2026-09-24 21:36:00 +08:00
1 parent 4d34b8c715
commit 2b823a32ca
24 files changed
+768 -72

No files matched your search

+27 -1
View File
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest'
import { toBlockViews } from './blockView'
import { commonIndent, reindentBlock, replaceLines } from './editText'
import { blockReplacement, commonIndent, reindentBlock, replaceLines } from './editText'
import { createTypeScriptAdapter } from './languages/typescript'
import { readFixture, WASM_DIR, withBlocks } from './testSupport'
@@ -44,3 +44,29 @@ describe('行替换', () => {
expect(replaceLines(source, view.startLine, view.endLine, view.code), view.id).toBe(source)
})
})
describe('块内修改写回的替换范围', () => {
const doc = ['class A {', ' run() {', ' go()', ' }', '}']
const lineAt = (n: number): string => doc[n]
it('从起始行行首替换到结束行行尾,新文本补回原来的缩进', () => {
expect(blockReplacement(lineAt, doc.length, 1, 2, 'run(): void {\n go(1)')).toEqual({
startLine: 1,
endLine: 2,
endCharacter: 8,
text: ' run(): void {\n go(1)',
unchanged: false,
})
})
it('改完和原来一样时标记 unchanged', () => {
expect(blockReplacement(lineAt, doc.length, 1, 2, 'run() {\n go()')?.unchanged).toBe(true)
})
it('行号已不在文档里时不替换', () => {
expect(blockReplacement(lineAt, doc.length, 3, 5, 'x')).toBeUndefined()
expect(blockReplacement(lineAt, doc.length, -1, 0, 'x')).toBeUndefined()
expect(blockReplacement(lineAt, doc.length, 2, 1, 'x')).toBeUndefined()
expect(blockReplacement(lineAt, doc.length, 0.5, 1, 'x')).toBeUndefined()
})
})