✨ feat(vscode): 代码阅读预览里实参值、return 这类一行译文里跨几行写的字典 / 列表按项拆开,各项带自己的实参表
This commit is contained in:
1 parent
b2c5309d1f
commit
907c4092c8
18 files changed
+515
-102
No files matched your search
@@ -160,6 +160,14 @@ describe('blockMarks', () => {
|
||||
expect(marks?.doc).toEqual({ markdown: [{ text: '旧说明', change: 'del' }] })
|
||||
})
|
||||
|
||||
it('一行译文下面拆开的各项逐行比:按第一列配,多出来的算加行,没了的算删行', () => {
|
||||
const before = textView([seg('返回 列表 2 项')], { items: [item('第 1 项'), item('第 2 项')] } as Partial<BlockView>)
|
||||
const after = textView([seg('返回 列表 1 项')], { items: [item('第 1 项')] } as Partial<BlockView>)
|
||||
const marks = blockMarks(before, after)
|
||||
expect(marks?.items?.removed).toEqual([{ after: 0, value: item('第 2 项') }])
|
||||
expect(blockMarks(after, before)?.items?.changed).toEqual({ 1: { added: true } })
|
||||
})
|
||||
|
||||
it('一块是属性表、一块是一行译文时没法逐行比', () => {
|
||||
expect(blockMarks(textView([seg('a')]), propertyView([row('名称', [seg('a')])]))).toBeUndefined()
|
||||
})
|
||||
@@ -178,6 +186,14 @@ describe('removedView / withoutSource', () => {
|
||||
expect(JSON.stringify(removed)).not.toMatch(/"offset"|"refers"/)
|
||||
})
|
||||
|
||||
it('一行译文下面拆开的各项、摊开实参的表照样带着,词不带源码下标', () => {
|
||||
const named = { cells: [[seg('第 1 项')], [seg('x', 'variable', 9)]] }
|
||||
const removed = removedView(textView([seg('返回 列表 1 项')], { items: [named], table: { columns: ['参数', '值'], items: [named] } } as Partial<BlockView>))
|
||||
expect('items' in removed && removed.items).toEqual([{ cells: [[seg('第 1 项')], [seg('x', 'variable')]] }])
|
||||
expect('table' in removed && removed.table?.items).toHaveLength(1)
|
||||
expect(JSON.stringify(removed)).not.toMatch(/"offset"/)
|
||||
})
|
||||
|
||||
it('框里的词也去掉下标,颜色留着', () => {
|
||||
const color = { dark: '#fff', light: '#000' }
|
||||
expect(withoutSource([{ style: 'iteration', label: '列表', segments: [{ ...seg('x', 'variable', 3), color }] }])).toEqual([
|
||||
|
||||
@@ -54,10 +54,14 @@ export interface RowDiff {
|
||||
items?: ItemsDiff
|
||||
}
|
||||
|
||||
/** 一块自己的内容(不算子块)改了哪些:属性表(一行译文的卡片是下面那几行 rows,「注释」一行)逐行,一行译文逐截,摊开实参的表逐行,说明逐词。 */
|
||||
/**
|
||||
* 一块自己的内容(不算子块)改了哪些:属性表(一行译文的卡片是下面那几行 rows,「注释」一行)逐行,一行译文逐截,
|
||||
* 译文下面拆开的各项、摊开实参的表逐行,说明逐词。
|
||||
*/
|
||||
export interface BlockMarks {
|
||||
rows?: RowsDiff
|
||||
translation?: TextDiff
|
||||
items?: ItemsDiff
|
||||
table?: ItemsDiff
|
||||
doc?: TextDiff
|
||||
}
|
||||
@@ -112,6 +116,7 @@ export function removedView(view: BlockView): BlockView {
|
||||
return {
|
||||
...base,
|
||||
translation: textWithoutSource(view.translation),
|
||||
...(view.items && { items: view.items.map(itemWithoutSource) }),
|
||||
...(view.table && { table: tableWithoutSource(view.table) }),
|
||||
...(view.doc && { doc: view.doc }),
|
||||
...(view.rows && { rows: view.rows.map(rowWithoutSource) }),
|
||||
@@ -305,7 +310,7 @@ export function rowsDiff(before: readonly PropertyRow[], after: readonly Propert
|
||||
}
|
||||
|
||||
/**
|
||||
* 配上的两块自己的内容(不算子块)比:属性表逐行,一行译文逐截,摊开实参的表逐行,说明逐词。
|
||||
* 配上的两块自己的内容(不算子块)比:属性表逐行,一行译文逐截,译文下面拆开的各项、摊开实参的表逐行,说明逐词。
|
||||
* 一样(或一块是属性表、一块是一行译文,没法逐行比)时是 undefined。
|
||||
*/
|
||||
export function blockMarks(before: BlockView, after: BlockView): BlockMarks | undefined {
|
||||
@@ -314,9 +319,10 @@ export function blockMarks(before: BlockView, after: BlockView): BlockMarks | un
|
||||
return rows && { rows }
|
||||
}
|
||||
const translation = textDiff(before.translation, after.translation)
|
||||
const items = itemsDiff(before.items, after.items)
|
||||
const table = itemsDiff(before.table?.items, after.table?.items)
|
||||
const doc = textDiff(before.doc ?? { markdown: '' }, after.doc ?? { markdown: '' })
|
||||
const rows = rowsDiff(before.rows ?? [], after.rows ?? [])
|
||||
const marks: BlockMarks = { ...(translation && { translation }), ...(table && { table }), ...(doc && { doc }), ...(rows && { rows }) }
|
||||
const marks: BlockMarks = { ...(translation && { translation }), ...(items && { items }), ...(table && { table }), ...(doc && { doc }), ...(rows && { rows }) }
|
||||
return Object.keys(marks).length > 0 ? marks : undefined
|
||||
}
|
||||
Reference in new issue
Block a user