diff --git a/src/main/kotlin/Diff.kt b/src/main/kotlin/Diff.kt index f4293ca..cfb1756 100644 --- a/src/main/kotlin/Diff.kt +++ b/src/main/kotlin/Diff.kt @@ -14,6 +14,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp import theme.primaryTextColor @Composable @@ -37,28 +38,45 @@ fun Diff(gitManager: GitManager, diffEntryType: DiffEntryType, onCloseDiffView: ) { Text("Close diff") } - val textLines = text.split("\n", "\r\n") - LazyColumn(modifier = Modifier - .fillMaxSize() - .padding(16.dp)) { - items(textLines) { line -> - val backgroundColor = if (line.startsWith("+")) { - Color(0x77a9d49b) - } else if (line.startsWith("-")) { - Color(0x77dea2a2) - } else { - MaterialTheme.colors.surface - } + SelectionContainer { + LazyColumn( + modifier = Modifier + .fillMaxSize() + .padding(16.dp) + ) { + items(text) { line -> + val isHunkLine = line.startsWith("@@") && line.endsWith("@@") + + val backgroundColor = when { + line.startsWith("+") -> { + Color(0x77a9d49b) + } + line.startsWith("-") -> { + Color(0x77dea2a2) + } + isHunkLine -> { + MaterialTheme.colors.background + } + else -> { + MaterialTheme.colors.surface + } + } + + val paddingTop = if (isHunkLine) + 32.dp + else + 0.dp - SelectionContainer { Text( text = line, modifier = Modifier + .padding(top = paddingTop) .background(backgroundColor) .fillMaxWidth(), color = MaterialTheme.colors.primaryTextColor, maxLines = 1, fontFamily = FontFamily.Monospace, + fontSize = 14.sp, ) } } diff --git a/src/main/kotlin/GitManager.kt b/src/main/kotlin/GitManager.kt index 2fba1d0..3d7faa0 100644 --- a/src/main/kotlin/GitManager.kt +++ b/src/main/kotlin/GitManager.kt @@ -126,7 +126,7 @@ class GitManager { val hasUncommitedChanges: StateFlow get() = statusManager.hasUncommitedChanges - fun diffFormat(diffEntryType: DiffEntryType): String { + fun diffFormat(diffEntryType: DiffEntryType): List { val diffEntry = diffEntryType.diffEntry val byteArrayOutputStream = ByteArrayOutputStream() @@ -144,7 +144,13 @@ class GitManager { formatter.flush() } - return byteArrayOutputStream.toString(Charsets.UTF_8) + val diff = byteArrayOutputStream.toString(Charsets.UTF_8) + + // TODO This is just a workaround, try to find properly which lines have to be displayed by using a custom diff + + return diff.split("\n", "\r\n").filterNot { + it.startsWith("diff --git") + } } fun pull() = managerScope.launch {