Changed how the diff list is created to improve scrollbar's behavior (used to change its size depending on the scroll position ???)

This commit is contained in:
Abdelilah El Aissaoui 2022-02-11 20:47:20 +01:00
parent c374ac77d5
commit 587843d246

View File

@ -132,7 +132,8 @@ fun SideDiff(entryContent: EntryContent) {
when (entryContent) { when (entryContent) {
EntryContent.Binary -> BinaryDiff() EntryContent.Binary -> BinaryDiff()
is EntryContent.ImageBinary -> ImageDiff(entryContent.tempFilePath) is EntryContent.ImageBinary -> ImageDiff(entryContent.tempFilePath)
else -> {} else -> {
}
// is EntryContent.Text -> //TODO maybe have a text view if the file was a binary before? // is EntryContent.Text -> //TODO maybe have a text view if the file was a binary before?
// TODO Show some info about this EntryContent.TooLargeEntry -> TODO() // TODO Show some info about this EntryContent.TooLargeEntry -> TODO()
} }
@ -162,29 +163,32 @@ fun TextDiff(diffEntryType: DiffEntryType, diffViewModel: DiffViewModel, diffRes
val hunks = diffResult.hunks val hunks = diffResult.hunks
val scrollState by diffViewModel.lazyListState.collectAsState() val scrollState by diffViewModel.lazyListState.collectAsState()
ScrollableLazyColumn( SelectionContainer {
modifier = Modifier ScrollableLazyColumn(
.fillMaxSize(), modifier = Modifier
state = scrollState .fillMaxSize(),
) { state = scrollState
items(hunks) { hunk -> ) {
HunkHeader(
hunk = hunk,
diffEntryType = diffEntryType,
diffViewModel = diffViewModel,
)
SelectionContainer { for (hunk in hunks) {
Column { item {
val oldHighestLineNumber = hunk.lines.maxOf { it.displayOldLineNumber } DisableSelection {
val newHighestLineNumber = hunk.lines.maxOf { it.displayNewLineNumber } HunkHeader(
val highestLineNumber = max(oldHighestLineNumber, newHighestLineNumber) hunk = hunk,
val highestLineNumberLength = highestLineNumber.toString().count() diffEntryType = diffEntryType,
diffViewModel = diffViewModel,
hunk.lines.forEach { line -> )
DiffLine(highestLineNumberLength, line)
} }
} }
val oldHighestLineNumber = hunk.lines.maxOf { it.displayOldLineNumber }
val newHighestLineNumber = hunk.lines.maxOf { it.displayNewLineNumber }
val highestLineNumber = max(oldHighestLineNumber, newHighestLineNumber)
val highestLineNumberLength = highestLineNumber.toString().count()
items(hunk.lines) { line ->
DiffLine(highestLineNumberLength, line)
}
} }
} }
} }