♻️ refactor(vscode): 代码阅读的块数据去掉没人用的「注释」一行下标 commentRow
This commit is contained in:
1 parent
ebea984852
commit
5cf96af740
6 files changed
+15
-27
No files matched your search
@@ -38,11 +38,6 @@ interface BlockViewBase {
|
||||
* 同一个 id 只留第一个。项目入口那一块的第一个换成入口(见 entries/entryMarks.ts)。webview 按这个画图标,不自己用种类查。
|
||||
*/
|
||||
concepts: BlockConcept[]
|
||||
/**
|
||||
* 「注释」一行(讲这块的普通注释,BlockShape.comments)排在第几行,0 起:属性表卡片是 properties 里的下标,
|
||||
* 一行译文的卡片是 rows 里的下标。没有注释就没有。
|
||||
*/
|
||||
commentRow?: number
|
||||
/** 「重写注释」写到哪(见 CommentTarget);不能写注释的块(嵌着的代码里的、语言没说行注释怎么写又还没有注释的)没有。 */
|
||||
commentTarget?: CommentTarget
|
||||
/** 库规则的卡片才有:筛选栏里这个种类的名字,卡片边框的颜色(RuleCard.badge)。图标在 concepts 里。预览同类块一样默认收起它的子块。 */
|
||||
@@ -279,12 +274,11 @@ function blockSpans(list: readonly CodeBlock[], source: string): BlockSpan[] {
|
||||
|
||||
/**
|
||||
* 「注释」一行插进属性表:排在第一行(名称这类讲它是谁的一行)后面,有说明(值是 Markdown 的一行)时排在说明后面。
|
||||
* 返回新的属性表和「注释」一行的下标。
|
||||
*/
|
||||
function withCommentRow(rows: readonly PropertyRow[], row: PropertyRow): { rows: PropertyRow[], at: number } {
|
||||
function withCommentRow(rows: readonly PropertyRow[], row: PropertyRow): PropertyRow[] {
|
||||
const doc = rows.findIndex(item => 'markdown' in item.value)
|
||||
const at = doc >= 0 ? doc + 1 : Math.min(1, rows.length)
|
||||
return { rows: [...rows.slice(0, at), row, ...rows.slice(at)], at }
|
||||
return [...rows.slice(0, at), row, ...rows.slice(at)]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -395,12 +389,9 @@ export function toBlockViews(
|
||||
return parts.length > 0 ? { label, value: { markdown: parts.join('\n\n') } } : undefined
|
||||
}
|
||||
/** 属性表卡片的属性表连同「注释」一行(见 withCommentRow)。 */
|
||||
function cardRows(block: CodeBlock, rows: PropertyRow[]): Pick<BlockView, 'commentRow'> & { properties: PropertyRow[] } {
|
||||
function cardRows(block: CodeBlock, rows: PropertyRow[]): { properties: PropertyRow[] } {
|
||||
const row = commentRow(block)
|
||||
if (!row)
|
||||
return { properties: rows }
|
||||
const { rows: properties, at } = withCommentRow(rows, row)
|
||||
return { properties, commentRow: at }
|
||||
return { properties: row ? withCommentRow(rows, row) : rows }
|
||||
}
|
||||
/** 「重写注释」写到哪(见 CommentTarget):块前面的普通注释换掉,没有就新写在块上面。 */
|
||||
function commentTarget(block: CodeBlock): Pick<BlockView, 'commentTarget'> {
|
||||
@@ -416,9 +407,9 @@ export function toBlockViews(
|
||||
return layerDocument.language.lineComment ? { commentTarget: { kind: 'insert', line: block.header.startRow } } : {}
|
||||
}
|
||||
/** 一行译文的卡片:译文、实参表、说明,有注释时下面再排「注释」一行。 */
|
||||
function textCard(block: TextBlock): Pick<BlockView, 'commentRow'> & ReturnType<typeof textView> & { rows?: PropertyRow[] } {
|
||||
function textCard(block: TextBlock): ReturnType<typeof textView> & { rows?: PropertyRow[] } {
|
||||
const row = commentRow(block)
|
||||
return { ...textView(block), ...(row && { rows: [row], commentRow: 0 }) }
|
||||
return { ...textView(block), ...(row && { rows: [row] }) }
|
||||
}
|
||||
|
||||
/** 块照它自己的样子(语言插件报的,或库规则认成的属性表块):编辑范围是 span,头部是块自己那部分,子块照常交给各规则看。scope 见 BlockAnchors.place */
|
||||
|
||||
Reference in new issue
Block a user