diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/extensions/RawTextExtensions.kt b/src/main/kotlin/com/jetpackduba/gitnuro/extensions/RawTextExtensions.kt index 700465c..95a22d1 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/extensions/RawTextExtensions.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/extensions/RawTextExtensions.kt @@ -4,7 +4,5 @@ import org.eclipse.jgit.diff.RawText import java.io.ByteArrayOutputStream fun RawText.lineAt(line: Int): String { - val outputStream = ByteArrayOutputStream() - this.writeLine(outputStream, line) - return outputStream.toString(Charsets.UTF_8) + return this.getString(line, line + 1, false) } \ No newline at end of file diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/git/diff/FormatHunksUseCase.kt b/src/main/kotlin/com/jetpackduba/gitnuro/git/diff/FormatHunksUseCase.kt index 9e19edf..9ac96cf 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/git/diff/FormatHunksUseCase.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/git/diff/FormatHunksUseCase.kt @@ -67,41 +67,20 @@ class FormatHunksUseCase @Inject constructor() { while (oldCurrentLine < oldEndLine || newCurrentLine < newEndLine) { if (oldCurrentLine < curEdit.beginA || endIdx + 1 < curIdx) { - var lineText = oldRawText.lineAt(oldCurrentLine) - - if ( - 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.orEmpty() - } + val lineText = oldRawText.lineAt(oldCurrentLine) lines.add(Line(lineText, oldCurrentLine, newCurrentLine, LineType.CONTEXT)) oldCurrentLine++ newCurrentLine++ } else if (oldCurrentLine < curEdit.endA) { - var lineText = oldRawText.lineAt(oldCurrentLine) - - if ( - 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.orEmpty() - } + val lineText = oldRawText.lineAt(oldCurrentLine) lines.add(Line(lineText, oldCurrentLine, newCurrentLine, LineType.REMOVED)) oldCurrentLine++ } else if (newCurrentLine < curEdit.endB) { - var lineText = newRawText.lineAt(newCurrentLine) - - if ( - 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.orEmpty() - } + val lineText = newRawText.lineAt(newCurrentLine) lines.add(Line(lineText, oldCurrentLine, newCurrentLine, LineType.ADDED))