🐛 fix(vscode): 代码阅读编辑父卡片时显示整块代码(含子块)

- 块的编辑范围改成它在源码里的完整范围:头部连同各子孙块、收尾括号,保存时按整段写回;子卡片只有它自己连同子孙
- 范围由宿主统一算(blockSpans),各语言插件同一条路:else / elif / catch 这类展平的兄弟块按各块开头切开整条语句,最后一块到语句结尾(Shell 的 fi 归它)
- 库规则卡片的编辑范围并进同一套算法,去掉 claimedShape
- 块编辑时它的子孙都不画(代码都在编辑框里),点「编辑」时重叠的祖先、子孙、共用一行的兄弟块退出编辑
- 问 AI 的外层块开头改用新加的 headerEndLine,位置记号照旧按头部算,已有问答不受影响
- 着色改成整份源码算一次、各块按行取,编辑范围变大后排视图数据不变慢
This commit is contained in:
cruldra committed 2026-09-30 07:24:10 +08:00
1 parent af63d2bc5c
commit 70ea22543f
13 files changed
+251 -143

No files matched your search

+2 -2
View File
@@ -131,7 +131,7 @@ describe('库规则:认领', () => {
? { kind: 'orm.card', badge: { label: '卡片', color: { dark: '#fff', light: '#000' }, icon: 'box' }, rows: [], absorbs: block.children.filter(child => child.kind === 'variable') }
: undefined }
const [, card] = await views(source, [fields])
expect(card.children.map(child => [child.kind, child.startLine, child.endLine])).toEqual([['function', 5, 5]])
expect(card.children.map(child => [child.kind, child.startLine, child.endLine])).toEqual([['function', 5, 6]])
expect([card.startLine, card.endLine]).toEqual([2, 8])
expect(replaceLines(source, card.startLine, card.endLine, card.code)).toBe(source)
const edited = replaceLines(source, card.startLine, card.endLine, card.code.replace('greet', 'hello').replace('String', 'Text'))
@@ -159,7 +159,7 @@ describe('库规则:认领', () => {
expect(reports[1]).toBe('库规则 throwing 看第 3 行的 class 块时出错,这块照常显示:坏了')
const alone = await views(MODEL, [throwing])
expect(alone[1]).toMatchObject({ kind: 'class', startLine: 2, endLine: 2 })
expect(alone[1]).toMatchObject({ kind: 'class', startLine: 2, headerEndLine: 2, endLine: 8 })
expect(alone[1].children.map(child => child.kind)).toEqual(['variable', 'comment', 'variable', 'function'])
})