Improved diff design

Also removed unecessary information and reduced font size to match better a desktop design
This commit is contained in:
Abdelilah El Aissaoui 2021-09-30 03:20:11 +02:00
parent 9e5627d5e9
commit 790845b3ec
2 changed files with 39 additions and 15 deletions

View File

@ -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
SelectionContainer {
LazyColumn(
modifier = Modifier
.fillMaxSize()
.padding(16.dp)) {
items(textLines) { line ->
val backgroundColor = if (line.startsWith("+")) {
.padding(16.dp)
) {
items(text) { line ->
val isHunkLine = line.startsWith("@@") && line.endsWith("@@")
val backgroundColor = when {
line.startsWith("+") -> {
Color(0x77a9d49b)
} else if (line.startsWith("-")) {
}
line.startsWith("-") -> {
Color(0x77dea2a2)
} else {
}
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,
)
}
}

View File

@ -126,7 +126,7 @@ class GitManager {
val hasUncommitedChanges: StateFlow<Boolean>
get() = statusManager.hasUncommitedChanges
fun diffFormat(diffEntryType: DiffEntryType): String {
fun diffFormat(diffEntryType: DiffEntryType): List<String> {
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 {