新增: Git 能力闭环(Diff 行号解析/分支只读展示/提交详情/写入后自动刷新变更视图)
- Diff 行号修复:解析 @@ -a,b +c,d @@ 头,计算旧/新行号(原恒空字符串) - 提交详情增强:显示父提交哈希/作者/日期/完整消息(git show -s --format=%P\t%an) - 分支只读展示:list_branches IPC + 变更面板顶部下拉查看分支(切换走 AI 工具) - AI 工具写入后自动跳转变更视图:监听 df-data-changed entity=file 切 Tab + 刷新
This commit is contained in:
@@ -130,21 +130,36 @@ interface DiffLine {
|
||||
newNum: string
|
||||
}
|
||||
|
||||
/** 解析 @@ -a,b +c,d @@ 头,返回旧/新行起始号 */
|
||||
function parseHunkHeader(line: string): { oldStart: number; newStart: number } {
|
||||
// 格式: @@ -10,7 +10,8 @@
|
||||
const m = line.match(/@@\s+-(\d+)(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s+@@/)
|
||||
if (!m) return { oldStart: 1, newStart: 1 }
|
||||
return { oldStart: parseInt(m[1], 10), newStart: parseInt(m[2], 10) }
|
||||
}
|
||||
|
||||
const diffLines = computed<DiffLine[]>(() => {
|
||||
if (!diffContent.value) return []
|
||||
const lines: DiffLine[] = []
|
||||
let oldNum = 0
|
||||
let newNum = 0
|
||||
for (const raw of diffContent.value.split('\n')) {
|
||||
if (raw.startsWith('@@')) {
|
||||
const h = parseHunkHeader(raw)
|
||||
oldNum = h.oldStart
|
||||
newNum = h.newStart
|
||||
lines.push({ type: 'hdr', prefix: '', text: raw, oldNum: '', newNum: '' })
|
||||
} else if (raw.startsWith('+')) {
|
||||
lines.push({ type: 'add', prefix: '+', text: raw.slice(1), oldNum: '', newNum: '' })
|
||||
lines.push({ type: 'add', prefix: '+', text: raw.slice(1), oldNum: '', newNum: String(newNum++) })
|
||||
} else if (raw.startsWith('-')) {
|
||||
lines.push({ type: 'del', prefix: '-', text: raw.slice(1), oldNum: '', newNum: '' })
|
||||
lines.push({ type: 'del', prefix: '-', text: raw.slice(1), oldNum: String(oldNum++), newNum: '' })
|
||||
} else if (raw.startsWith('\\')) {
|
||||
// No newline at end of file 等元信息
|
||||
lines.push({ type: 'ctx', prefix: '', text: raw, oldNum: '', newNum: '' })
|
||||
} else {
|
||||
lines.push({ type: 'ctx', prefix: ' ', text: raw, oldNum: '', newNum: '' })
|
||||
// 空串(diff 头前的空行)或 context 行(以空格开头)
|
||||
const text = raw.startsWith(' ') ? raw.slice(1) : raw
|
||||
lines.push({ type: 'ctx', prefix: ' ', text, oldNum: String(oldNum++), newNum: String(newNum++) })
|
||||
}
|
||||
}
|
||||
return lines
|
||||
|
||||
Reference in New Issue
Block a user