✨ feat(vscode): 代码阅读把推导式换成按读的顺序重排的遍历小框

This commit is contained in:
cruldra committed 2026-09-26 16:15:09 +08:00
1 parent 677fb7da1f
commit 6416cdf714
16 files changed
+641 -91

No files matched your search

@@ -1,5 +1,5 @@
import type { Click, Highlight } from './occurrences'
import type { BlockView, Occurrence, PreviewText, PropertyItem, Segment, WebviewToExtension } from './types'
import type { BlockView, Inline, Occurrence, PreviewText, PropertyItem, Segment, WebviewToExtension } from './types'
import { describe, expect, it } from 'vitest'
import { toBlockViews } from '../../../src/codeReader/blockView'
import { createPythonAdapter } from '../../../src/codeReader/languages/python'
@@ -205,12 +205,17 @@ describe('occurrences:高亮的状态', () => {
})
})
/** 框拆开,框里的词接在前后的词中间:SegmentText 同样一段段画框里的词。 */
function inlineSegments(pieces: Inline[]): Segment[] {
return pieces.flatMap(piece => 'role' in piece ? [piece] : inlineSegments(piece.segments))
}
function textSegments(text: PreviewText): Segment[] {
return 'markdown' in text ? [] : text
return 'markdown' in text ? [] : inlineSegments(text)
}
function itemSegments(items: PropertyItem[] | undefined): Segment[] {
return (items ?? []).flatMap(item => [...item.cells.flat(), ...itemSegments(item.items)])
return (items ?? []).flatMap(item => [...inlineSegments(item.cells.flat()), ...itemSegments(item.items)])
}
/** 预览里画出来的所有段,按页面上从上到下的顺序:每块的属性表或译文,再是它的子块。 */