Fixed hunk stage on files with a single line without lineDelimiter
This commit is contained in:
parent
d055060483
commit
c31b1a9d6b
@ -148,14 +148,19 @@ class StatusManager @Inject constructor(
|
|||||||
|
|
||||||
private fun getTextLines(rawFile: RawText): List<String> {
|
private fun getTextLines(rawFile: RawText): List<String> {
|
||||||
val content = rawFile.rawContent.toString(Charsets.UTF_8)//.removeSuffix(rawFile.lineDelimiter)
|
val content = rawFile.rawContent.toString(Charsets.UTF_8)//.removeSuffix(rawFile.lineDelimiter)
|
||||||
|
val lineDelimiter: String? = rawFile.lineDelimiter
|
||||||
|
|
||||||
var splitted: List<String> = content.split(rawFile.lineDelimiter).toMutableList().apply {
|
var splitted: List<String> = if (lineDelimiter != null) {
|
||||||
|
content.split(lineDelimiter).toMutableList().apply {
|
||||||
if (this.last() == "")
|
if (this.last() == "")
|
||||||
removeLast()
|
removeLast()
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
listOf(content)
|
||||||
|
}
|
||||||
|
|
||||||
splitted = splitted.mapIndexed { index, line ->
|
splitted = splitted.mapIndexed { index, line ->
|
||||||
val lineWithBreak = line + rawFile.lineDelimiter
|
val lineWithBreak = line +lineDelimiter.orEmpty()
|
||||||
|
|
||||||
if (index == splitted.count() - 1 && !content.endsWith(lineWithBreak)) {
|
if (index == splitted.count() - 1 && !content.endsWith(lineWithBreak)) {
|
||||||
line
|
line
|
||||||
|
@ -129,7 +129,7 @@ class HunkDiffGenerator @AssistedInject constructor(
|
|||||||
oldCurrentLine < oldRawText.size() - 1 || // If it's not the last
|
oldCurrentLine < oldRawText.size() - 1 || // If it's not the last
|
||||||
(oldCurrentLine == oldRawText.size() - 1 && !oldRawText.isMissingNewlineAtEnd) // Or is the last and contains new line at the end
|
(oldCurrentLine == oldRawText.size() - 1 && !oldRawText.isMissingNewlineAtEnd) // Or is the last and contains new line at the end
|
||||||
) {
|
) {
|
||||||
lineText += oldRawText.lineDelimiter
|
lineText += oldRawText.lineDelimiter.orEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
lines.add(Line(lineText, oldCurrentLine, newCurrentLine, LineType.REMOVED))
|
lines.add(Line(lineText, oldCurrentLine, newCurrentLine, LineType.REMOVED))
|
||||||
@ -142,7 +142,7 @@ class HunkDiffGenerator @AssistedInject constructor(
|
|||||||
newCurrentLine < newRawText.size() - 1 || // If it's not the last
|
newCurrentLine < newRawText.size() - 1 || // If it's not the last
|
||||||
(newCurrentLine == newRawText.size() - 1 && !newRawText.isMissingNewlineAtEnd) // Or is the last and contains new line at the end
|
(newCurrentLine == newRawText.size() - 1 && !newRawText.isMissingNewlineAtEnd) // Or is the last and contains new line at the end
|
||||||
) {
|
) {
|
||||||
lineText += newRawText.lineDelimiter
|
lineText += newRawText.lineDelimiter.orEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
lines.add(Line(lineText, oldCurrentLine, newCurrentLine, LineType.ADDED))
|
lines.add(Line(lineText, oldCurrentLine, newCurrentLine, LineType.ADDED))
|
||||||
|
Loading…
Reference in New Issue
Block a user