Fixed hunk stage on files with a single line without lineDelimiter
This commit is contained in:
parent
d055060483
commit
c31b1a9d6b
@ -148,16 +148,21 @@ class StatusManager @Inject constructor(
|
||||
|
||||
private fun getTextLines(rawFile: RawText): List<String> {
|
||||
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 {
|
||||
if(this.last() == "")
|
||||
removeLast()
|
||||
var splitted: List<String> = if (lineDelimiter != null) {
|
||||
content.split(lineDelimiter).toMutableList().apply {
|
||||
if (this.last() == "")
|
||||
removeLast()
|
||||
}
|
||||
} else {
|
||||
listOf(content)
|
||||
}
|
||||
|
||||
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
|
||||
} else
|
||||
lineWithBreak
|
||||
|
@ -129,7 +129,7 @@ class HunkDiffGenerator @AssistedInject constructor(
|
||||
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
|
||||
) {
|
||||
lineText += oldRawText.lineDelimiter
|
||||
lineText += oldRawText.lineDelimiter.orEmpty()
|
||||
}
|
||||
|
||||
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 && !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))
|
||||
|
Loading…
Reference in New Issue
Block a user