parent
5c63d2eaf7
commit
75b4adeb76
@ -75,11 +75,8 @@ class FormatDiffUseCase @Inject constructor(
|
|||||||
|
|
||||||
// If we can, generate text diff (if one of the files has never been a binary file)
|
// If we can, generate text diff (if one of the files has never been a binary file)
|
||||||
val hasGeneratedTextDiff = canGenerateTextDiffUseCase(rawOld, rawNew) { oldRawText, newRawText ->
|
val hasGeneratedTextDiff = canGenerateTextDiffUseCase(rawOld, rawNew) { oldRawText, newRawText ->
|
||||||
if (isDisplayFullFile) {
|
diffResult =
|
||||||
TODO()
|
DiffResult.Text(diffEntry, formatHunksUseCase(fileHeader, oldRawText, newRawText, isDisplayFullFile))
|
||||||
} else {
|
|
||||||
diffResult = DiffResult.Text(diffEntry, formatHunksUseCase(fileHeader, oldRawText, newRawText))
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import javax.inject.Inject
|
|||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
private const val CONTEXT_LINES = 2
|
private const val CONTEXT_LINES = 3
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generator of [Hunk] lists from [DiffEntry]
|
* Generator of [Hunk] lists from [DiffEntry]
|
||||||
@ -19,24 +19,48 @@ class FormatHunksUseCase @Inject constructor() {
|
|||||||
fileHeader: FileHeader,
|
fileHeader: FileHeader,
|
||||||
rawOld: RawText,
|
rawOld: RawText,
|
||||||
rawNew: RawText,
|
rawNew: RawText,
|
||||||
|
isDisplayFullFile: Boolean,
|
||||||
): List<Hunk> {
|
): List<Hunk> {
|
||||||
return if (fileHeader.patchType == PatchType.UNIFIED)
|
return if (fileHeader.patchType == PatchType.UNIFIED)
|
||||||
format(fileHeader.toEditList(), rawOld, rawNew)
|
format(fileHeader.toEditList(), rawOld, rawNew, isDisplayFullFile)
|
||||||
else
|
else
|
||||||
emptyList()
|
emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun format(edits: EditList, oldRawText: RawText, newRawText: RawText): List<Hunk> {
|
private fun format(
|
||||||
|
edits: EditList,
|
||||||
|
oldRawText: RawText,
|
||||||
|
newRawText: RawText,
|
||||||
|
isDisplayFullFile: Boolean
|
||||||
|
): List<Hunk> {
|
||||||
var curIdx = 0
|
var curIdx = 0
|
||||||
val hunksList = mutableListOf<Hunk>()
|
val hunksList = mutableListOf<Hunk>()
|
||||||
while (curIdx < edits.size) {
|
while (curIdx < edits.count()) {
|
||||||
var curEdit = edits[curIdx]
|
var curEdit = edits[curIdx]
|
||||||
val endIdx = findCombinedEnd(edits, curIdx)
|
|
||||||
|
val endIdx: Int = if (isDisplayFullFile)
|
||||||
|
edits.lastIndex
|
||||||
|
else
|
||||||
|
findCombinedEnd(edits, curIdx)
|
||||||
|
|
||||||
val endEdit = edits[endIdx]
|
val endEdit = edits[endIdx]
|
||||||
var oldCurrentLine = max(0, curEdit.beginA - CONTEXT_LINES)
|
|
||||||
var newCurrentLine = max(0, curEdit.beginB - CONTEXT_LINES)
|
var oldCurrentLine: Int
|
||||||
val oldEndLine = min(oldRawText.size(), endEdit.endA + CONTEXT_LINES)
|
var newCurrentLine: Int
|
||||||
val newEndLine = min(newRawText.size(), endEdit.endB + CONTEXT_LINES)
|
val oldEndLine: Int
|
||||||
|
val newEndLine: Int
|
||||||
|
|
||||||
|
if (isDisplayFullFile) {
|
||||||
|
oldCurrentLine = 0
|
||||||
|
newCurrentLine = 0
|
||||||
|
oldEndLine = oldRawText.size()
|
||||||
|
newEndLine = newRawText.size()
|
||||||
|
} else {
|
||||||
|
oldCurrentLine = max(0, curEdit.beginA - CONTEXT_LINES)
|
||||||
|
newCurrentLine = max(0, curEdit.beginB - CONTEXT_LINES)
|
||||||
|
oldEndLine = min(oldRawText.size(), endEdit.endA + CONTEXT_LINES)
|
||||||
|
newEndLine = min(newRawText.size(), endEdit.endB + CONTEXT_LINES)
|
||||||
|
}
|
||||||
|
|
||||||
val headerText = createHunkHeader(oldCurrentLine, oldEndLine, newCurrentLine, newEndLine)
|
val headerText = createHunkHeader(oldCurrentLine, oldEndLine, newCurrentLine, newEndLine)
|
||||||
val lines = mutableListOf<Line>()
|
val lines = mutableListOf<Line>()
|
||||||
|
Loading…
Reference in New Issue
Block a user