Add version mcmeta diff page (#428)

* Add version mcmeta diff page

* Add toggle for word wrapping

* Fix diff view on mobile

* Use full layout width on version details

* Show image and audio diffs

* Add word_wrap locale
This commit is contained in:
Misode
2023-10-09 22:09:36 +02:00
committed by GitHub
parent ddf54174d1
commit ddd00dd731
19 changed files with 474 additions and 119 deletions

View File

@@ -545,3 +545,39 @@ export function composeMatrix(translation: Vector, leftRotation: quat, scale: Ve
.scale(scale)
.mul(Matrix4.fromQuat(rightRotation))
}
export interface PatchLine {
line: string
before?: number
after?: number
}
export function parseGitPatch(patch: string) {
const source = patch.split('\n')
const result: PatchLine[] = []
let before = 1
let after = 1
for (let i = 0; i < source.length; i += 1) {
const line = source[i]
if (line.startsWith('@')) {
const match = line.match(/^@@ -(\d+)(?:,(?:\d+))? \+(\d+)(?:,(?:\d+))? @@/)
if (!match) throw new Error(`Invalid patch pattern at line ${i+1}: ${line}`)
result.push({ line })
before = Number(match[1])
after = Number(match[2])
} else if (line.startsWith(' ')) {
result.push({ line, before, after })
before += 1
after += 1
} else if (line.startsWith('+')) {
result.push({ line, after })
after += 1
} else if (line.startsWith('-')) {
result.push({ line, before })
before += 1
} else if (!line.startsWith('\\')) {
throw new Error(`Invalid patch, got ${line.charAt(0)} at line ${i+1}`)
}
}
return result
}