Renamed DiffEntryType to DiffType
This commit is contained in:
parent
a542e38ae2
commit
6dd55bcc84
@ -6,8 +6,8 @@ import com.jetpackduba.gitnuro.git.workspace.StatusEntry
|
||||
import com.jetpackduba.gitnuro.git.workspace.StatusType
|
||||
import org.eclipse.jgit.diff.DiffEntry
|
||||
|
||||
sealed interface DiffEntryType {
|
||||
class CommitDiff(val diffEntry: DiffEntry) : DiffEntryType {
|
||||
sealed interface DiffType {
|
||||
class CommitDiff(val diffEntry: DiffEntry) : DiffType {
|
||||
override val filePath: String
|
||||
get() = diffEntry.filePath
|
||||
|
||||
@ -15,7 +15,7 @@ sealed interface DiffEntryType {
|
||||
get() = diffEntry.toStatusType()
|
||||
}
|
||||
|
||||
sealed class UncommittedDiff(val statusEntry: StatusEntry) : DiffEntryType {
|
||||
sealed class UncommittedDiff(val statusEntry: StatusEntry) : DiffType {
|
||||
override val filePath: String
|
||||
get() = statusEntry.filePath
|
||||
|
@ -1,17 +1,15 @@
|
||||
package com.jetpackduba.gitnuro.git.diff
|
||||
|
||||
import com.jetpackduba.gitnuro.extensions.filePath
|
||||
import com.jetpackduba.gitnuro.git.DiffEntryType
|
||||
import com.jetpackduba.gitnuro.git.DiffType
|
||||
import com.jetpackduba.gitnuro.git.EntryContent
|
||||
import com.jetpackduba.gitnuro.git.submodules.GetSubmodulesUseCase
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.eclipse.jgit.api.Git
|
||||
import org.eclipse.jgit.diff.DiffEntry
|
||||
import org.eclipse.jgit.diff.DiffFormatter
|
||||
import org.eclipse.jgit.dircache.DirCacheIterator
|
||||
import org.eclipse.jgit.treewalk.FileTreeIterator
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.InvalidObjectException
|
||||
import javax.inject.Inject
|
||||
|
||||
@ -19,41 +17,18 @@ class FormatDiffUseCase @Inject constructor(
|
||||
private val formatHunksUseCase: FormatHunksUseCase,
|
||||
private val getDiffContentUseCase: GetDiffContentUseCase,
|
||||
private val canGenerateTextDiffUseCase: CanGenerateTextDiffUseCase,
|
||||
private val getDiffEntryForUncommittedDiffUseCase: GetDiffEntryForUncommittedDiffUseCase,
|
||||
private val getDiffEntryFromDiffTypeUseCase: GetDiffEntryFromDiffTypeUseCase,
|
||||
private val getSubmodulesUseCase: GetSubmodulesUseCase,
|
||||
) {
|
||||
suspend operator fun invoke(
|
||||
git: Git,
|
||||
diffEntryType: DiffEntryType,
|
||||
diffType: DiffType,
|
||||
isDisplayFullFile: Boolean
|
||||
): DiffResult = withContext(Dispatchers.IO) {
|
||||
val byteArrayOutputStream = ByteArrayOutputStream()
|
||||
val repository = git.repository
|
||||
val diffEntry: DiffEntry
|
||||
val submodules = getSubmodulesUseCase(git)
|
||||
|
||||
DiffFormatter(byteArrayOutputStream).use { formatter ->
|
||||
formatter.setRepository(repository)
|
||||
|
||||
val oldTree = DirCacheIterator(repository.readDirCache())
|
||||
val newTree = FileTreeIterator(repository)
|
||||
|
||||
if (diffEntryType is DiffEntryType.UnstagedDiff)
|
||||
formatter.scan(oldTree, newTree)
|
||||
|
||||
diffEntry = when (diffEntryType) {
|
||||
is DiffEntryType.CommitDiff -> {
|
||||
diffEntryType.diffEntry
|
||||
}
|
||||
|
||||
is DiffEntryType.UncommittedDiff -> {
|
||||
getDiffEntryForUncommittedDiffUseCase(git, diffEntryType)
|
||||
}
|
||||
}
|
||||
|
||||
formatter.format(diffEntry)
|
||||
formatter.flush()
|
||||
}
|
||||
val diffEntry = getDiffEntryFromDiffTypeUseCase(git, diffType)
|
||||
|
||||
var diffResult: DiffResult
|
||||
val submoduleStatus = submodules[diffEntry.filePath]
|
||||
@ -64,7 +39,7 @@ class FormatDiffUseCase @Inject constructor(
|
||||
val oldTree: DirCacheIterator?
|
||||
val newTree: FileTreeIterator?
|
||||
|
||||
if (diffEntryType is DiffEntryType.UnstagedDiff) {
|
||||
if (diffType is DiffType.UnstagedDiff) {
|
||||
oldTree = DirCacheIterator(repository.readDirCache())
|
||||
newTree = FileTreeIterator(repository)
|
||||
} else {
|
||||
|
@ -0,0 +1,44 @@
|
||||
package com.jetpackduba.gitnuro.git.diff
|
||||
|
||||
import com.jetpackduba.gitnuro.git.DiffType
|
||||
import org.eclipse.jgit.api.Git
|
||||
import org.eclipse.jgit.diff.DiffEntry
|
||||
import org.eclipse.jgit.diff.DiffFormatter
|
||||
import org.eclipse.jgit.dircache.DirCacheIterator
|
||||
import org.eclipse.jgit.treewalk.FileTreeIterator
|
||||
import java.io.ByteArrayOutputStream
|
||||
import javax.inject.Inject
|
||||
|
||||
class GetDiffEntryFromDiffTypeUseCase @Inject constructor(
|
||||
private val getDiffEntryFromStatusEntryUseCase: GetDiffEntryFromStatusEntryUseCase,
|
||||
) {
|
||||
suspend operator fun invoke(git: Git, diffType: DiffType): DiffEntry {
|
||||
val repository = git.repository
|
||||
val byteArrayOutputStream = ByteArrayOutputStream()
|
||||
|
||||
return DiffFormatter(byteArrayOutputStream).use { formatter ->
|
||||
formatter.setRepository(repository)
|
||||
|
||||
val oldTree = DirCacheIterator(repository.readDirCache())
|
||||
val newTree = FileTreeIterator(repository)
|
||||
|
||||
if (diffType is DiffType.UnstagedDiff)
|
||||
formatter.scan(oldTree, newTree)
|
||||
|
||||
val diffEntry = when (diffType) {
|
||||
is DiffType.CommitDiff -> {
|
||||
diffType.diffEntry
|
||||
}
|
||||
|
||||
is DiffType.UncommittedDiff -> {
|
||||
getDiffEntryFromStatusEntryUseCase(git, diffType is DiffType.StagedDiff, diffType.statusEntry)
|
||||
}
|
||||
}
|
||||
|
||||
formatter.format(diffEntry)
|
||||
formatter.flush()
|
||||
|
||||
diffEntry
|
||||
}
|
||||
}
|
||||
}
|
@ -2,9 +2,9 @@ package com.jetpackduba.gitnuro.git.diff
|
||||
|
||||
import com.jetpackduba.gitnuro.exceptions.MissingDiffEntryException
|
||||
import com.jetpackduba.gitnuro.extensions.isMerging
|
||||
import com.jetpackduba.gitnuro.git.DiffEntryType
|
||||
import com.jetpackduba.gitnuro.git.branches.GetCurrentBranchUseCase
|
||||
import com.jetpackduba.gitnuro.git.repository.GetRepositoryStateUseCase
|
||||
import com.jetpackduba.gitnuro.git.workspace.StatusEntry
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.eclipse.jgit.api.Git
|
||||
@ -12,25 +12,24 @@ import org.eclipse.jgit.treewalk.EmptyTreeIterator
|
||||
import org.eclipse.jgit.treewalk.filter.PathFilter
|
||||
import javax.inject.Inject
|
||||
|
||||
class GetDiffEntryForUncommittedDiffUseCase @Inject constructor(
|
||||
class GetDiffEntryFromStatusEntryUseCase @Inject constructor(
|
||||
private val getRepositoryStateUseCase: GetRepositoryStateUseCase,
|
||||
private val getCurrentBranchUseCase: GetCurrentBranchUseCase,
|
||||
) {
|
||||
suspend operator fun invoke(
|
||||
git: Git,
|
||||
diffEntryType: DiffEntryType.UncommittedDiff,
|
||||
isCached: Boolean,
|
||||
statusEntry: StatusEntry,
|
||||
) = withContext(Dispatchers.IO) {
|
||||
val statusEntry = diffEntryType.statusEntry
|
||||
val cached = diffEntryType is DiffEntryType.StagedDiff
|
||||
val firstDiffEntry = git.diff()
|
||||
.setPathFilter(PathFilter.create(statusEntry.filePath))
|
||||
.setCached(cached).apply {
|
||||
.setCached(isCached).apply {
|
||||
val repositoryState = getRepositoryStateUseCase(git)
|
||||
if (
|
||||
getCurrentBranchUseCase(git) == null &&
|
||||
!repositoryState.isMerging &&
|
||||
!repositoryState.isRebasing &&
|
||||
cached
|
||||
isCached
|
||||
) {
|
||||
setOldTree(EmptyTreeIterator()) // Required if the repository is empty
|
||||
}
|
@ -23,9 +23,7 @@ import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.jetpackduba.gitnuro.AppIcons
|
||||
import com.jetpackduba.gitnuro.extensions.*
|
||||
import com.jetpackduba.gitnuro.git.DiffEntryType
|
||||
import com.jetpackduba.gitnuro.theme.backgroundSelected
|
||||
import com.jetpackduba.gitnuro.theme.linesHeight
|
||||
import com.jetpackduba.gitnuro.git.DiffType
|
||||
import com.jetpackduba.gitnuro.theme.onBackgroundSecondary
|
||||
import com.jetpackduba.gitnuro.theme.tertiarySurface
|
||||
import com.jetpackduba.gitnuro.ui.components.*
|
||||
@ -45,7 +43,7 @@ fun CommitChanges(
|
||||
commitChangesViewModel: CommitChangesViewModel,
|
||||
selectedItem: SelectedItem.CommitBasedItem,
|
||||
onDiffSelected: (DiffEntry) -> Unit,
|
||||
diffSelected: DiffEntryType?,
|
||||
diffSelected: DiffType?,
|
||||
onBlame: (String) -> Unit,
|
||||
onHistory: (String) -> Unit,
|
||||
) {
|
||||
@ -97,7 +95,7 @@ fun CommitChanges(
|
||||
@Composable
|
||||
private fun CommitChangesView(
|
||||
commitChangesStatus: CommitChangesStateUi.Loaded,
|
||||
diffSelected: DiffEntryType?,
|
||||
diffSelected: DiffType?,
|
||||
changesListScroll: LazyListState,
|
||||
textScroll: ScrollState,
|
||||
showSearch: Boolean,
|
||||
@ -380,7 +378,7 @@ fun Author(
|
||||
@Composable
|
||||
fun ListCommitLogChanges(
|
||||
diffEntries: List<DiffEntry>,
|
||||
diffSelected: DiffEntryType?,
|
||||
diffSelected: DiffType?,
|
||||
changesListScroll: LazyListState,
|
||||
onDiffSelected: (DiffEntry) -> Unit,
|
||||
onGenerateContextMenu: (DiffEntry) -> List<ContextMenuElement>,
|
||||
@ -396,7 +394,7 @@ fun ListCommitLogChanges(
|
||||
iconColor = diffEntry.iconColor,
|
||||
parentDirectoryPath = diffEntry.parentDirectoryPath,
|
||||
fileName = diffEntry.fileName,
|
||||
isSelected = diffSelected is DiffEntryType.CommitDiff && diffSelected.diffEntry == diffEntry,
|
||||
isSelected = diffSelected is DiffType.CommitDiff && diffSelected.diffEntry == diffEntry,
|
||||
onClick = { onDiffSelected(diffEntry) },
|
||||
onDoubleClick = {},
|
||||
onGenerateContextMenu = { onGenerateContextMenu(diffEntry) },
|
||||
@ -409,7 +407,7 @@ fun ListCommitLogChanges(
|
||||
@Composable
|
||||
fun TreeCommitLogChanges(
|
||||
treeItems: List<TreeItem<DiffEntry>>,
|
||||
diffSelected: DiffEntryType?,
|
||||
diffSelected: DiffType?,
|
||||
changesListScroll: LazyListState,
|
||||
onDiffSelected: (DiffEntry) -> Unit,
|
||||
onDirectoryClicked: (TreeItem.Dir) -> Unit,
|
||||
@ -424,7 +422,7 @@ fun TreeCommitLogChanges(
|
||||
CommitTreeItemEntry(
|
||||
entry = entry,
|
||||
isSelected = entry is TreeItem.File &&
|
||||
diffSelected is DiffEntryType.CommitDiff &&
|
||||
diffSelected is DiffType.CommitDiff &&
|
||||
diffSelected.diffEntry == entry.data,
|
||||
onFileClick = { onDiffSelected(it) },
|
||||
onDirectoryClick = { onDirectoryClicked(it) },
|
||||
|
@ -170,7 +170,7 @@ fun HistoryContentLoaded(
|
||||
when (val diffResult = viewDiffResult.diffResult) {
|
||||
is DiffResult.Text -> {
|
||||
HunkUnifiedTextDiff(
|
||||
diffEntryType = viewDiffResult.diffEntryType,
|
||||
diffType = viewDiffResult.diffType,
|
||||
scrollState = scrollState,
|
||||
diffResult = diffResult,
|
||||
onUnstageHunk = { _, _ -> },
|
||||
@ -183,7 +183,7 @@ fun HistoryContentLoaded(
|
||||
|
||||
is DiffResult.TextSplit -> {
|
||||
HunkSplitTextDiff(
|
||||
diffEntryType = viewDiffResult.diffEntryType,
|
||||
diffType = viewDiffResult.diffType,
|
||||
scrollState = scrollState,
|
||||
diffResult = diffResult,
|
||||
onUnstageHunk = { _, _ -> },
|
||||
|
@ -17,7 +17,7 @@ import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.jetpackduba.gitnuro.AppConstants
|
||||
import com.jetpackduba.gitnuro.extensions.handMouseClickable
|
||||
import com.jetpackduba.gitnuro.git.DiffEntryType
|
||||
import com.jetpackduba.gitnuro.git.DiffType
|
||||
import com.jetpackduba.gitnuro.git.rebase.RebaseInteractiveState
|
||||
import com.jetpackduba.gitnuro.keybindings.KeybindingOption
|
||||
import com.jetpackduba.gitnuro.keybindings.matchesBinding
|
||||
@ -226,7 +226,7 @@ private fun BottomInfoBar(
|
||||
@Composable
|
||||
fun RepoContent(
|
||||
tabViewModel: TabViewModel,
|
||||
diffSelected: DiffEntryType?,
|
||||
diffSelected: DiffType?,
|
||||
selectedItem: SelectedItem,
|
||||
repositoryState: RepositoryState,
|
||||
blameState: BlameState,
|
||||
@ -257,7 +257,7 @@ fun RepoContent(
|
||||
@Composable
|
||||
fun MainContentView(
|
||||
tabViewModel: TabViewModel,
|
||||
diffSelected: DiffEntryType?,
|
||||
diffSelected: DiffType?,
|
||||
selectedItem: SelectedItem,
|
||||
repositoryState: RepositoryState,
|
||||
blameState: BlameState,
|
||||
@ -348,9 +348,9 @@ fun MainContentView(
|
||||
|
||||
tabViewModel.newDiffSelected = if (diffEntry != null) {
|
||||
if (repositoryState == RepositoryState.SAFE)
|
||||
DiffEntryType.SafeStagedDiff(diffEntry)
|
||||
DiffType.SafeStagedDiff(diffEntry)
|
||||
else
|
||||
DiffEntryType.UnsafeStagedDiff(diffEntry)
|
||||
DiffType.UnsafeStagedDiff(diffEntry)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
@ -359,9 +359,9 @@ fun MainContentView(
|
||||
tabViewModel.minimizeBlame()
|
||||
|
||||
if (repositoryState == RepositoryState.SAFE)
|
||||
tabViewModel.newDiffSelected = DiffEntryType.SafeUnstagedDiff(diffEntry)
|
||||
tabViewModel.newDiffSelected = DiffType.SafeUnstagedDiff(diffEntry)
|
||||
else
|
||||
tabViewModel.newDiffSelected = DiffEntryType.UnsafeUnstagedDiff(diffEntry)
|
||||
tabViewModel.newDiffSelected = DiffType.UnsafeUnstagedDiff(diffEntry)
|
||||
},
|
||||
onBlameFile = { tabViewModel.blameFile(it) },
|
||||
onHistoryFile = { tabViewModel.fileHistory(it) }
|
||||
@ -375,7 +375,7 @@ fun MainContentView(
|
||||
diffSelected = diffSelected,
|
||||
onDiffSelected = { diffEntry ->
|
||||
tabViewModel.minimizeBlame()
|
||||
tabViewModel.newDiffSelected = DiffEntryType.CommitDiff(diffEntry)
|
||||
tabViewModel.newDiffSelected = DiffType.CommitDiff(diffEntry)
|
||||
},
|
||||
onBlame = { tabViewModel.blameFile(it) },
|
||||
onHistory = { tabViewModel.fileHistory(it) },
|
||||
|
@ -31,7 +31,7 @@ import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.jetpackduba.gitnuro.AppIcons
|
||||
import com.jetpackduba.gitnuro.extensions.*
|
||||
import com.jetpackduba.gitnuro.git.DiffEntryType
|
||||
import com.jetpackduba.gitnuro.git.DiffType
|
||||
import com.jetpackduba.gitnuro.git.rebase.RebaseInteractiveState
|
||||
import com.jetpackduba.gitnuro.git.workspace.StatusEntry
|
||||
import com.jetpackduba.gitnuro.keybindings.KeybindingOption
|
||||
@ -54,7 +54,7 @@ import org.eclipse.jgit.lib.RepositoryState
|
||||
@Composable
|
||||
fun UncommittedChanges(
|
||||
statusViewModel: StatusViewModel,
|
||||
selectedEntryType: DiffEntryType?,
|
||||
selectedEntryType: DiffType?,
|
||||
repositoryState: RepositoryState,
|
||||
onStagedDiffEntrySelected: (StatusEntry?) -> Unit,
|
||||
onUnstagedDiffEntrySelected: (StatusEntry) -> Unit,
|
||||
@ -321,7 +321,7 @@ fun ColumnScope.StagedView(
|
||||
showSearchUnstaged: Boolean,
|
||||
searchFilterUnstaged: TextFieldValue,
|
||||
stagedListState: LazyListState,
|
||||
selectedEntryType: DiffEntryType?,
|
||||
selectedEntryType: DiffType?,
|
||||
onSearchFilterToggled: (Boolean) -> Unit,
|
||||
onDiffEntryOptionSelected: (StatusEntry) -> Unit,
|
||||
onDiffEntrySelected: (StatusEntry) -> Unit,
|
||||
@ -369,7 +369,7 @@ fun ColumnScope.StagedView(
|
||||
onTreeDirectoryAction = onTreeDirectoryAction,
|
||||
onTreeEntries = { it.staged },
|
||||
onListEntries = { it.staged },
|
||||
onGetSelectedEntry = { if (selectedEntryType is DiffEntryType.StagedDiff) selectedEntryType else null }
|
||||
onGetSelectedEntry = { if (selectedEntryType is DiffType.StagedDiff) selectedEntryType else null },
|
||||
)
|
||||
}
|
||||
|
||||
@ -379,7 +379,7 @@ fun ColumnScope.UnstagedView(
|
||||
showSearchUnstaged: Boolean,
|
||||
searchFilterUnstaged: TextFieldValue,
|
||||
unstagedListState: LazyListState,
|
||||
selectedEntryType: DiffEntryType?,
|
||||
selectedEntryType: DiffType?,
|
||||
onSearchFilterToggled: (Boolean) -> Unit,
|
||||
onDiffEntryOptionSelected: (StatusEntry) -> Unit,
|
||||
onDiffEntrySelected: (StatusEntry) -> Unit,
|
||||
@ -427,7 +427,7 @@ fun ColumnScope.UnstagedView(
|
||||
onTreeDirectoryAction = onTreeDirectoryAction,
|
||||
onTreeEntries = { it.unstaged },
|
||||
onListEntries = { it.unstaged },
|
||||
onGetSelectedEntry = { if (selectedEntryType is DiffEntryType.UnstagedDiff) selectedEntryType else null }
|
||||
onGetSelectedEntry = { if (selectedEntryType is DiffType.UnstagedDiff) selectedEntryType else null },
|
||||
)
|
||||
}
|
||||
|
||||
@ -444,7 +444,7 @@ fun ColumnScope.NeutralView(
|
||||
showSearchUnstaged: Boolean,
|
||||
searchFilterUnstaged: TextFieldValue,
|
||||
listState: LazyListState,
|
||||
selectedEntryType: DiffEntryType?,
|
||||
selectedEntryType: DiffType?,
|
||||
onTreeEntries: (StageStateUi.TreeLoaded) -> List<TreeItem<StatusEntry>>,
|
||||
onListEntries: (StageStateUi.ListLoaded) -> List<StatusEntry>,
|
||||
onSearchFilterToggled: (Boolean) -> Unit,
|
||||
@ -459,7 +459,7 @@ fun ColumnScope.NeutralView(
|
||||
onAlternateShowAsTree: () -> Unit,
|
||||
onTreeDirectoryClicked: (String) -> Unit,
|
||||
onTreeDirectoryAction: (String) -> Unit,
|
||||
onGetSelectedEntry: () -> DiffEntryType?,
|
||||
onGetSelectedEntry: () -> DiffType?,
|
||||
) {
|
||||
val modifier = Modifier
|
||||
.weight(5f)
|
||||
@ -495,7 +495,7 @@ fun ColumnScope.NeutralView(
|
||||
onAllAction = onAllAction,
|
||||
onTreeDirectoryClicked = { onTreeDirectoryClicked(it.fullPath) },
|
||||
allActionTitle = allActionTitle,
|
||||
selectedEntryType = if (selectedEntryType is DiffEntryType.UnstagedDiff) selectedEntryType else null,
|
||||
selectedEntryType = if (selectedEntryType is DiffType.UnstagedDiff) selectedEntryType else null,
|
||||
onAlternateShowAsTree = onAlternateShowAsTree,
|
||||
onGenerateDirectoryContextMenu = { dir ->
|
||||
statusDirEntriesContextMenuItems(
|
||||
@ -798,7 +798,7 @@ private fun EntriesList(
|
||||
onAllAction: () -> Unit,
|
||||
onAlternateShowAsTree: () -> Unit,
|
||||
allActionTitle: String,
|
||||
selectedEntryType: DiffEntryType?,
|
||||
selectedEntryType: DiffType?,
|
||||
) {
|
||||
Column(
|
||||
modifier = modifier
|
||||
@ -827,7 +827,7 @@ private fun EntriesList(
|
||||
) {
|
||||
items(statusEntries, key = { it.filePath }) { statusEntry ->
|
||||
val isEntrySelected = selectedEntryType != null &&
|
||||
selectedEntryType is DiffEntryType.UncommittedDiff && // Added for smartcast
|
||||
selectedEntryType is DiffType.UncommittedDiff && // Added for smartcast
|
||||
selectedEntryType.statusEntry == statusEntry
|
||||
UncommittedFileEntry(
|
||||
statusEntry = statusEntry,
|
||||
@ -870,7 +870,7 @@ private fun TreeEntriesList(
|
||||
onAlternateShowAsTree: () -> Unit,
|
||||
onTreeDirectoryClicked: (TreeItem.Dir) -> Unit,
|
||||
allActionTitle: String,
|
||||
selectedEntryType: DiffEntryType?,
|
||||
selectedEntryType: DiffType?,
|
||||
) {
|
||||
Column(
|
||||
modifier = modifier
|
||||
@ -899,7 +899,7 @@ private fun TreeEntriesList(
|
||||
items(statusEntries, key = { it.fullPath }) { treeEntry ->
|
||||
val isEntrySelected = treeEntry is TreeItem.File<StatusEntry> &&
|
||||
selectedEntryType != null &&
|
||||
selectedEntryType is DiffEntryType.UncommittedDiff && // Added for smartcast
|
||||
selectedEntryType is DiffType.UncommittedDiff && // Added for smartcast
|
||||
selectedEntryType.statusEntry == treeEntry.data
|
||||
|
||||
UncommittedTreeItemEntry(
|
||||
|
@ -38,7 +38,7 @@ import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.jetpackduba.gitnuro.AppIcons
|
||||
import com.jetpackduba.gitnuro.extensions.*
|
||||
import com.jetpackduba.gitnuro.git.DiffEntryType
|
||||
import com.jetpackduba.gitnuro.git.DiffType
|
||||
import com.jetpackduba.gitnuro.git.EntryContent
|
||||
import com.jetpackduba.gitnuro.git.animatedImages
|
||||
import com.jetpackduba.gitnuro.git.diff.DiffResult
|
||||
@ -87,7 +87,7 @@ fun Diff(
|
||||
onCloseDiffView: () -> Unit,
|
||||
) {
|
||||
val diffResultState = diffViewModel.diffResult.collectAsState()
|
||||
val diffType by diffViewModel.diffTypeFlow.collectAsState()
|
||||
val textDiffType by diffViewModel.diffTypeFlow.collectAsState()
|
||||
val isDisplayFullFile by diffViewModel.isDisplayFullFile.collectAsState()
|
||||
val viewDiffResult = diffResultState.value ?: return
|
||||
val focusRequester = remember { FocusRequester() }
|
||||
@ -112,15 +112,15 @@ fun Diff(
|
||||
}
|
||||
|
||||
is ViewDiffResult.Loaded -> {
|
||||
val diffEntryType = viewDiffResult.diffEntryType
|
||||
val diffType = viewDiffResult.diffType
|
||||
val diffEntry = viewDiffResult.diffResult.diffEntry
|
||||
val diffResult = viewDiffResult.diffResult
|
||||
|
||||
DiffHeader(
|
||||
diffEntryType = diffEntryType,
|
||||
diffType = diffType,
|
||||
diffEntry = diffEntry,
|
||||
onCloseDiffView = onCloseDiffView,
|
||||
diffType = diffType,
|
||||
textDiffType = textDiffType,
|
||||
isTextDiff = diffResult is DiffResult.TextDiff,
|
||||
isDisplayFullFile = isDisplayFullFile,
|
||||
onStageFile = { diffViewModel.stageFile(it) },
|
||||
@ -133,7 +133,7 @@ fun Diff(
|
||||
|
||||
when (diffResult) {
|
||||
is DiffResult.TextSplit -> HunkSplitTextDiff(
|
||||
diffEntryType = diffEntryType,
|
||||
diffType = diffType,
|
||||
scrollState = scrollState,
|
||||
diffResult = diffResult,
|
||||
onUnstageHunk = { entry, hunk ->
|
||||
@ -146,9 +146,9 @@ fun Diff(
|
||||
diffViewModel.resetHunk(entry, hunk)
|
||||
},
|
||||
onUnStageLine = { entry, hunk, line ->
|
||||
if (diffEntryType is DiffEntryType.UnstagedDiff)
|
||||
if (diffType is DiffType.UnstagedDiff)
|
||||
diffViewModel.stageHunkLine(entry, hunk, line)
|
||||
else if (diffEntryType is DiffEntryType.StagedDiff)
|
||||
else if (diffType is DiffType.StagedDiff)
|
||||
diffViewModel.unstageHunkLine(entry, hunk, line)
|
||||
},
|
||||
onDiscardLine = { entry, hunk, line ->
|
||||
@ -157,7 +157,7 @@ fun Diff(
|
||||
)
|
||||
|
||||
is DiffResult.Text -> HunkUnifiedTextDiff(
|
||||
diffEntryType = diffEntryType,
|
||||
diffType = diffType,
|
||||
scrollState = scrollState,
|
||||
diffResult = diffResult,
|
||||
onUnstageHunk = { entry, hunk ->
|
||||
@ -170,9 +170,9 @@ fun Diff(
|
||||
diffViewModel.resetHunk(entry, hunk)
|
||||
},
|
||||
onUnStageLine = { entry, hunk, line ->
|
||||
if (diffEntryType is DiffEntryType.UnstagedDiff)
|
||||
if (diffType is DiffType.UnstagedDiff)
|
||||
diffViewModel.stageHunkLine(entry, hunk, line)
|
||||
else if (diffEntryType is DiffEntryType.StagedDiff)
|
||||
else if (diffType is DiffType.StagedDiff)
|
||||
diffViewModel.unstageHunkLine(entry, hunk, line)
|
||||
},
|
||||
onDiscardLine = { entry, hunk, line ->
|
||||
@ -427,7 +427,7 @@ fun BinaryDiff() {
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
fun HunkUnifiedTextDiff(
|
||||
diffEntryType: DiffEntryType,
|
||||
diffType: DiffType,
|
||||
scrollState: LazyListState,
|
||||
diffResult: DiffResult.Text,
|
||||
onUnstageHunk: (DiffEntry, Hunk) -> Unit,
|
||||
@ -455,7 +455,7 @@ fun HunkUnifiedTextDiff(
|
||||
DisableSelection {
|
||||
HunkHeader(
|
||||
header = hunk.header,
|
||||
diffEntryType = diffEntryType,
|
||||
diffType = diffType,
|
||||
onUnstageHunk = { onUnstageHunk(diffResult.diffEntry, hunk) },
|
||||
onStageHunk = { onStageHunk(diffResult.diffEntry, hunk) },
|
||||
onResetHunk = { onResetHunk(diffResult.diffEntry, hunk) },
|
||||
@ -471,14 +471,14 @@ fun HunkUnifiedTextDiff(
|
||||
items(hunk.lines) { line ->
|
||||
DiffContextMenu(
|
||||
selectedText = selectedText,
|
||||
diffEntryType = diffEntryType,
|
||||
diffType = diffType,
|
||||
onDiscardLine = { onDiscardLine(diffResult.diffEntry, hunk, line) },
|
||||
line = line,
|
||||
) {
|
||||
DiffLine(
|
||||
highestLineNumberLength,
|
||||
line,
|
||||
diffEntryType = diffEntryType,
|
||||
diffType = diffType,
|
||||
onActionTriggered = {
|
||||
onUnStageLine(
|
||||
diffResult.diffEntry,
|
||||
@ -498,7 +498,7 @@ fun HunkUnifiedTextDiff(
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
fun HunkSplitTextDiff(
|
||||
diffEntryType: DiffEntryType,
|
||||
diffType: DiffType,
|
||||
scrollState: LazyListState,
|
||||
diffResult: DiffResult.TextSplit,
|
||||
onUnstageHunk: (DiffEntry, Hunk) -> Unit,
|
||||
@ -532,7 +532,7 @@ fun HunkSplitTextDiff(
|
||||
DisableSelection {
|
||||
HunkHeader(
|
||||
header = splitHunk.sourceHunk.header,
|
||||
diffEntryType = diffEntryType,
|
||||
diffType = diffType,
|
||||
onUnstageHunk = { onUnstageHunk(diffResult.diffEntry, splitHunk.sourceHunk) },
|
||||
onStageHunk = { onStageHunk(diffResult.diffEntry, splitHunk.sourceHunk) },
|
||||
onResetHunk = { onResetHunk(diffResult.diffEntry, splitHunk.sourceHunk) },
|
||||
@ -551,7 +551,7 @@ fun HunkSplitTextDiff(
|
||||
oldLine = linesPair.first,
|
||||
newLine = linesPair.second,
|
||||
selectableSide = selectableSide,
|
||||
diffEntryType = diffEntryType,
|
||||
diffType = diffType,
|
||||
selectedText = selectedText,
|
||||
onActionTriggered = { line ->
|
||||
onUnStageLine(diffResult.diffEntry, splitHunk.sourceHunk, line)
|
||||
@ -586,7 +586,7 @@ fun SplitDiffLine(
|
||||
oldLine: Line?,
|
||||
newLine: Line?,
|
||||
selectableSide: SelectableSide,
|
||||
diffEntryType: DiffEntryType,
|
||||
diffType: DiffType,
|
||||
selectedText: AnnotatedString,
|
||||
onChangeSelectableSide: (SelectableSide) -> Unit,
|
||||
onActionTriggered: (Line) -> Unit,
|
||||
@ -606,7 +606,7 @@ fun SplitDiffLine(
|
||||
currentSelectableSide = selectableSide,
|
||||
lineSelectableSide = SelectableSide.OLD,
|
||||
onChangeSelectableSide = onChangeSelectableSide,
|
||||
diffEntryType = diffEntryType,
|
||||
diffType = diffType,
|
||||
onActionTriggered = { if (oldLine != null) onActionTriggered(oldLine) },
|
||||
selectedText = selectedText,
|
||||
onDiscardLine = onDiscardLine,
|
||||
@ -628,7 +628,7 @@ fun SplitDiffLine(
|
||||
currentSelectableSide = selectableSide,
|
||||
lineSelectableSide = SelectableSide.NEW,
|
||||
onChangeSelectableSide = onChangeSelectableSide,
|
||||
diffEntryType = diffEntryType,
|
||||
diffType = diffType,
|
||||
onActionTriggered = { if (newLine != null) onActionTriggered(newLine) },
|
||||
selectedText = selectedText,
|
||||
onDiscardLine = onDiscardLine,
|
||||
@ -646,7 +646,7 @@ fun SplitDiffLineSide(
|
||||
displayLineNumber: Int,
|
||||
currentSelectableSide: SelectableSide,
|
||||
lineSelectableSide: SelectableSide,
|
||||
diffEntryType: DiffEntryType,
|
||||
diffType: DiffType,
|
||||
selectedText: AnnotatedString,
|
||||
onChangeSelectableSide: (SelectableSide) -> Unit,
|
||||
onActionTriggered: () -> Unit,
|
||||
@ -692,14 +692,14 @@ fun SplitDiffLineSide(
|
||||
DiffContextMenu(
|
||||
selectedText,
|
||||
line,
|
||||
diffEntryType,
|
||||
diffType,
|
||||
onDiscardLine = { onDiscardLine(line) },
|
||||
) {
|
||||
SplitDiffLine(
|
||||
highestLineNumberLength = highestLineNumberLength,
|
||||
line = line,
|
||||
lineNumber = displayLineNumber,
|
||||
diffEntryType = diffEntryType,
|
||||
diffType = diffType,
|
||||
onActionTriggered = onActionTriggered,
|
||||
)
|
||||
}
|
||||
@ -712,7 +712,7 @@ fun SplitDiffLineSide(
|
||||
fun DiffContextMenu(
|
||||
selectedText: AnnotatedString,
|
||||
line: Line,
|
||||
diffEntryType: DiffEntryType,
|
||||
diffType: DiffType,
|
||||
onDiscardLine: () -> Unit,
|
||||
content: @Composable () -> Unit,
|
||||
) {
|
||||
@ -721,8 +721,8 @@ fun DiffContextMenu(
|
||||
items = {
|
||||
if (
|
||||
line.lineType != LineType.CONTEXT &&
|
||||
diffEntryType is DiffEntryType.UnstagedDiff &&
|
||||
diffEntryType.statusType == StatusType.MODIFIED
|
||||
diffType is DiffType.UnstagedDiff &&
|
||||
diffType.statusType == StatusType.MODIFIED
|
||||
) {
|
||||
listOf(
|
||||
ContextMenuElement.ContextTextEntry(
|
||||
@ -750,7 +750,7 @@ enum class SelectableSide {
|
||||
@Composable
|
||||
fun HunkHeader(
|
||||
header: String,
|
||||
diffEntryType: DiffEntryType,
|
||||
diffType: DiffType,
|
||||
onUnstageHunk: () -> Unit,
|
||||
onStageHunk: () -> Unit,
|
||||
onResetHunk: () -> Unit,
|
||||
@ -772,12 +772,12 @@ fun HunkHeader(
|
||||
|
||||
// Hunks options are only visible when repository is a normal state (not during merge/rebase)
|
||||
if (
|
||||
(diffEntryType is DiffEntryType.SafeStagedDiff || diffEntryType is DiffEntryType.SafeUnstagedDiff) &&
|
||||
diffEntryType.statusType == StatusType.MODIFIED
|
||||
(diffType is DiffType.SafeStagedDiff || diffType is DiffType.SafeUnstagedDiff) &&
|
||||
diffType.statusType == StatusType.MODIFIED
|
||||
) {
|
||||
val buttonText: String
|
||||
val color: Color
|
||||
if (diffEntryType is DiffEntryType.StagedDiff) {
|
||||
if (diffType is DiffType.StagedDiff) {
|
||||
buttonText = "Unstage hunk"
|
||||
color = MaterialTheme.colors.error
|
||||
} else {
|
||||
@ -785,7 +785,7 @@ fun HunkHeader(
|
||||
color = MaterialTheme.colors.primary
|
||||
}
|
||||
|
||||
if (diffEntryType is DiffEntryType.UnstagedDiff) {
|
||||
if (diffType is DiffType.UnstagedDiff) {
|
||||
SecondaryButton(
|
||||
text = "Discard hunk",
|
||||
backgroundButton = MaterialTheme.colors.error,
|
||||
@ -800,7 +800,7 @@ fun HunkHeader(
|
||||
backgroundButton = color,
|
||||
modifier = Modifier.padding(horizontal = 16.dp),
|
||||
onClick = {
|
||||
if (diffEntryType is DiffEntryType.StagedDiff) {
|
||||
if (diffType is DiffType.StagedDiff) {
|
||||
onUnstageHunk()
|
||||
} else {
|
||||
onStageHunk()
|
||||
@ -813,9 +813,9 @@ fun HunkHeader(
|
||||
|
||||
@Composable
|
||||
private fun DiffHeader(
|
||||
diffEntryType: DiffEntryType,
|
||||
diffType: DiffType,
|
||||
diffEntry: DiffEntry,
|
||||
diffType: TextDiffType,
|
||||
textDiffType: TextDiffType,
|
||||
isDisplayFullFile: Boolean,
|
||||
isTextDiff: Boolean,
|
||||
onCloseDiffView: () -> Unit,
|
||||
@ -879,18 +879,18 @@ private fun DiffHeader(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(16.dp)
|
||||
) {
|
||||
if (diffEntryType.statusType != StatusType.ADDED && diffEntryType.statusType != StatusType.REMOVED && isTextDiff) {
|
||||
if (diffType.statusType != StatusType.ADDED && diffType.statusType != StatusType.REMOVED && isTextDiff) {
|
||||
DiffTypeButtons(
|
||||
diffType = diffType,
|
||||
diffType = textDiffType,
|
||||
isDisplayFullFile = isDisplayFullFile,
|
||||
onChangeDiffType = onChangeDiffType,
|
||||
onDisplayFullFile = onDisplayFullFile,
|
||||
)
|
||||
}
|
||||
|
||||
if (diffEntryType is DiffEntryType.UncommittedDiff) {
|
||||
if (diffType is DiffType.UncommittedDiff) {
|
||||
UncommittedDiffFileHeaderButtons(
|
||||
diffEntryType,
|
||||
diffType,
|
||||
onUnstageFile = onUnstageFile,
|
||||
onStageFile = onStageFile
|
||||
)
|
||||
@ -995,14 +995,14 @@ fun DiffTypeButtons(
|
||||
|
||||
@Composable
|
||||
fun UncommittedDiffFileHeaderButtons(
|
||||
diffEntryType: DiffEntryType.UncommittedDiff,
|
||||
diffType: DiffType.UncommittedDiff,
|
||||
onUnstageFile: (StatusEntry) -> Unit,
|
||||
onStageFile: (StatusEntry) -> Unit
|
||||
) {
|
||||
val buttonText: String
|
||||
val color: Color
|
||||
|
||||
if (diffEntryType is DiffEntryType.StagedDiff) {
|
||||
if (diffType is DiffType.StagedDiff) {
|
||||
buttonText = "Unstage file"
|
||||
color = MaterialTheme.colors.error
|
||||
} else {
|
||||
@ -1014,10 +1014,10 @@ fun UncommittedDiffFileHeaderButtons(
|
||||
text = buttonText,
|
||||
backgroundButton = color,
|
||||
onClick = {
|
||||
if (diffEntryType is DiffEntryType.StagedDiff) {
|
||||
onUnstageFile(diffEntryType.statusEntry)
|
||||
if (diffType is DiffType.StagedDiff) {
|
||||
onUnstageFile(diffType.statusEntry)
|
||||
} else {
|
||||
onStageFile(diffEntryType.statusEntry)
|
||||
onStageFile(diffType.statusEntry)
|
||||
}
|
||||
}
|
||||
)
|
||||
@ -1064,7 +1064,7 @@ private fun PathOnlyDiffHeader(
|
||||
fun DiffLine(
|
||||
highestLineNumberLength: Int,
|
||||
line: Line,
|
||||
diffEntryType: DiffEntryType,
|
||||
diffType: DiffType,
|
||||
onActionTriggered: () -> Unit,
|
||||
) {
|
||||
val backgroundColor = when (line.lineType) {
|
||||
@ -1100,7 +1100,7 @@ fun DiffLine(
|
||||
)
|
||||
}
|
||||
|
||||
DiffLineText(line, diffEntryType, onActionTriggered = onActionTriggered)
|
||||
DiffLineText(line, diffType, onActionTriggered = onActionTriggered)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1109,7 +1109,7 @@ fun SplitDiffLine(
|
||||
highestLineNumberLength: Int,
|
||||
line: Line,
|
||||
lineNumber: Int,
|
||||
diffEntryType: DiffEntryType,
|
||||
diffType: DiffType,
|
||||
onActionTriggered: () -> Unit,
|
||||
) {
|
||||
val backgroundColor = when (line.lineType) {
|
||||
@ -1129,27 +1129,27 @@ fun SplitDiffLine(
|
||||
)
|
||||
}
|
||||
|
||||
DiffLineText(line, diffEntryType, onActionTriggered = onActionTriggered)
|
||||
DiffLineText(line, diffType, onActionTriggered = onActionTriggered)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Composable
|
||||
fun DiffLineText(line: Line, diffEntryType: DiffEntryType, onActionTriggered: () -> Unit) {
|
||||
fun DiffLineText(line: Line, diffType: DiffType, onActionTriggered: () -> Unit) {
|
||||
val text = line.text
|
||||
val hoverInteraction = remember { MutableInteractionSource() }
|
||||
val isHovered by hoverInteraction.collectIsHoveredAsState()
|
||||
|
||||
Box(modifier = Modifier.hoverable(hoverInteraction)) {
|
||||
if (isHovered && diffEntryType is DiffEntryType.UncommittedDiff && line.lineType != LineType.CONTEXT) {
|
||||
val color: Color = if (diffEntryType is DiffEntryType.StagedDiff) {
|
||||
if (isHovered && diffType is DiffType.UncommittedDiff && line.lineType != LineType.CONTEXT) {
|
||||
val color: Color = if (diffType is DiffType.StagedDiff) {
|
||||
MaterialTheme.colors.error
|
||||
} else {
|
||||
MaterialTheme.colors.primary
|
||||
}
|
||||
|
||||
val iconName = remember(diffEntryType) {
|
||||
if (diffEntryType is DiffEntryType.StagedDiff) {
|
||||
val iconName = remember(diffType) {
|
||||
if (diffType is DiffType.StagedDiff) {
|
||||
AppIcons.REMOVE
|
||||
} else {
|
||||
AppIcons.ADD
|
||||
|
@ -3,7 +3,7 @@ package com.jetpackduba.gitnuro.viewmodels
|
||||
import androidx.compose.foundation.lazy.LazyListState
|
||||
import com.jetpackduba.gitnuro.exceptions.MissingDiffEntryException
|
||||
import com.jetpackduba.gitnuro.extensions.delayedStateChange
|
||||
import com.jetpackduba.gitnuro.git.DiffEntryType
|
||||
import com.jetpackduba.gitnuro.git.DiffType
|
||||
import com.jetpackduba.gitnuro.git.RefreshType
|
||||
import com.jetpackduba.gitnuro.git.TabState
|
||||
import com.jetpackduba.gitnuro.git.diff.*
|
||||
@ -45,7 +45,7 @@ class DiffViewModel @Inject constructor(
|
||||
val diffTypeFlow = settings.textDiffTypeFlow
|
||||
val isDisplayFullFile = settings.diffDisplayFullFileFlow
|
||||
|
||||
private var diffEntryType: DiffEntryType? = null
|
||||
private var diffType: DiffType? = null
|
||||
private var diffJob: Job? = null
|
||||
|
||||
init {
|
||||
@ -53,7 +53,7 @@ class DiffViewModel @Inject constructor(
|
||||
diffTypeFlow
|
||||
.drop(1) // Ignore the first time the flow triggers, we only care about updates
|
||||
.collect {
|
||||
val diffEntryType = this@DiffViewModel.diffEntryType
|
||||
val diffEntryType = this@DiffViewModel.diffType
|
||||
if (diffEntryType != null) {
|
||||
updateDiff(diffEntryType)
|
||||
}
|
||||
@ -64,7 +64,7 @@ class DiffViewModel @Inject constructor(
|
||||
isDisplayFullFile
|
||||
.drop(1) // Ignore the first time the flow triggers, we only care about updates
|
||||
.collect {
|
||||
val diffEntryType = this@DiffViewModel.diffEntryType
|
||||
val diffEntryType = this@DiffViewModel.diffType
|
||||
if (diffEntryType != null) {
|
||||
updateDiff(diffEntryType)
|
||||
}
|
||||
@ -78,7 +78,7 @@ class DiffViewModel @Inject constructor(
|
||||
) {
|
||||
val diffResultValue = diffResult.value
|
||||
if (diffResultValue is ViewDiffResult.Loaded) {
|
||||
updateDiff(diffResultValue.diffEntryType)
|
||||
updateDiff(diffResultValue.diffType)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -91,24 +91,24 @@ class DiffViewModel @Inject constructor(
|
||||
)
|
||||
)
|
||||
|
||||
fun updateDiff(diffEntryType: DiffEntryType) {
|
||||
fun updateDiff(diffType: DiffType) {
|
||||
diffJob = tabState.runOperation(refreshType = RefreshType.NONE) { git ->
|
||||
this.diffEntryType = diffEntryType
|
||||
this.diffType = diffType
|
||||
|
||||
var oldDiffEntryType: DiffEntryType? = null
|
||||
var oldDiffType: DiffType? = null
|
||||
val oldDiffResult = _diffResult.value
|
||||
|
||||
if (oldDiffResult is ViewDiffResult.Loaded) {
|
||||
oldDiffEntryType = oldDiffResult.diffEntryType
|
||||
oldDiffType = oldDiffResult.diffType
|
||||
}
|
||||
|
||||
// If it's a different file or different state (index or workdir), reset the scroll state
|
||||
if (
|
||||
oldDiffEntryType?.filePath != diffEntryType.filePath ||
|
||||
oldDiffEntryType is DiffEntryType.UncommittedDiff &&
|
||||
diffEntryType is DiffEntryType.UncommittedDiff &&
|
||||
oldDiffEntryType.statusEntry.filePath == diffEntryType.statusEntry.filePath &&
|
||||
oldDiffEntryType::class != diffEntryType::class
|
||||
oldDiffType?.filePath != diffType.filePath ||
|
||||
oldDiffType is DiffType.UncommittedDiff &&
|
||||
diffType is DiffType.UncommittedDiff &&
|
||||
oldDiffType.statusEntry.filePath == diffType.statusEntry.filePath &&
|
||||
oldDiffType::class != diffType::class
|
||||
) {
|
||||
lazyListState.value = LazyListState(
|
||||
0,
|
||||
@ -121,9 +121,9 @@ class DiffViewModel @Inject constructor(
|
||||
try {
|
||||
delayedStateChange(
|
||||
delayMs = if (isFirstLoad) 0 else DIFF_MIN_TIME_IN_MS_TO_SHOW_LOAD,
|
||||
onDelayTriggered = { _diffResult.value = ViewDiffResult.Loading(diffEntryType.filePath) }
|
||||
onDelayTriggered = { _diffResult.value = ViewDiffResult.Loading(diffType.filePath) }
|
||||
) {
|
||||
val diffFormat = formatDiffUseCase(git, diffEntryType, isDisplayFullFile.value)
|
||||
val diffFormat = formatDiffUseCase(git, diffType, isDisplayFullFile.value)
|
||||
val diffEntry = diffFormat.diffEntry
|
||||
if (
|
||||
diffTypeFlow.value == TextDiffType.SPLIT &&
|
||||
@ -133,11 +133,11 @@ class DiffViewModel @Inject constructor(
|
||||
) {
|
||||
val splitHunkList = generateSplitHunkFromDiffResultUseCase(diffFormat)
|
||||
_diffResult.value = ViewDiffResult.Loaded(
|
||||
diffEntryType,
|
||||
diffType,
|
||||
DiffResult.TextSplit(diffEntry, splitHunkList)
|
||||
)
|
||||
} else {
|
||||
_diffResult.value = ViewDiffResult.Loaded(diffEntryType, diffFormat)
|
||||
_diffResult.value = ViewDiffResult.Loaded(diffType, diffFormat)
|
||||
}
|
||||
}
|
||||
} catch (ex: Exception) {
|
||||
|
@ -4,7 +4,7 @@ import androidx.compose.foundation.lazy.LazyListState
|
||||
import com.jetpackduba.gitnuro.TaskType
|
||||
import com.jetpackduba.gitnuro.exceptions.MissingDiffEntryException
|
||||
import com.jetpackduba.gitnuro.extensions.filePath
|
||||
import com.jetpackduba.gitnuro.git.DiffEntryType
|
||||
import com.jetpackduba.gitnuro.git.DiffType
|
||||
import com.jetpackduba.gitnuro.git.RefreshType
|
||||
import com.jetpackduba.gitnuro.git.TabState
|
||||
import com.jetpackduba.gitnuro.git.diff.DiffResult
|
||||
@ -61,14 +61,14 @@ class HistoryViewModel @Inject constructor(
|
||||
if (diffResult is DiffResult.Text && newDiffType == TextDiffType.SPLIT) { // Current is unified and new is split
|
||||
val hunksList = generateSplitHunkFromDiffResultUseCase(diffResult)
|
||||
_viewDiffResult.value = ViewDiffResult.Loaded(
|
||||
diffEntryType = viewDiffResult.diffEntryType,
|
||||
diffType = viewDiffResult.diffType,
|
||||
diffResult = DiffResult.TextSplit(diffResult.diffEntry, hunksList)
|
||||
)
|
||||
} else if (diffResult is DiffResult.TextSplit && newDiffType == TextDiffType.UNIFIED) { // Current is split and new is unified
|
||||
val hunksList = diffResult.hunks.map { it.sourceHunk }
|
||||
|
||||
_viewDiffResult.value = ViewDiffResult.Loaded(
|
||||
diffEntryType = viewDiffResult.diffEntryType,
|
||||
diffType = viewDiffResult.diffType,
|
||||
diffResult = DiffResult.Text(diffResult.diffEntry, hunksList)
|
||||
)
|
||||
}
|
||||
@ -109,11 +109,11 @@ class HistoryViewModel @Inject constructor(
|
||||
return@runOperation
|
||||
}
|
||||
|
||||
val diffEntryType = DiffEntryType.CommitDiff(diffEntry)
|
||||
val diffType = DiffType.CommitDiff(diffEntry)
|
||||
|
||||
val diffResult = formatDiffUseCase(
|
||||
git,
|
||||
diffEntryType,
|
||||
diffType,
|
||||
false
|
||||
) // TODO This hardcoded false should be changed when the UI is implemented
|
||||
val textDiffType = settings.textDiffType
|
||||
@ -123,7 +123,7 @@ class HistoryViewModel @Inject constructor(
|
||||
} else
|
||||
diffResult
|
||||
|
||||
_viewDiffResult.value = ViewDiffResult.Loaded(diffEntryType, formattedDiffResult)
|
||||
_viewDiffResult.value = ViewDiffResult.Loaded(diffType, formattedDiffResult)
|
||||
} catch (ex: Exception) {
|
||||
if (ex is MissingDiffEntryException) {
|
||||
tabState.refreshData(refreshType = RefreshType.UNCOMMITTED_CHANGES)
|
||||
|
@ -89,10 +89,10 @@ class TabViewModel @Inject constructor(
|
||||
|
||||
val credentialsState: StateFlow<CredentialsState> = credentialsStateManager.credentialsState
|
||||
|
||||
private val _diffSelected = MutableStateFlow<DiffEntryType?>(null)
|
||||
val diffSelected: StateFlow<DiffEntryType?> = _diffSelected
|
||||
private val _diffSelected = MutableStateFlow<DiffType?>(null)
|
||||
val diffSelected: StateFlow<DiffType?> = _diffSelected
|
||||
|
||||
var newDiffSelected: DiffEntryType?
|
||||
var newDiffSelected: DiffType?
|
||||
get() = diffSelected.value
|
||||
set(value) {
|
||||
_diffSelected.value = value
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.jetpackduba.gitnuro.viewmodels
|
||||
|
||||
import com.jetpackduba.gitnuro.git.DiffEntryType
|
||||
import com.jetpackduba.gitnuro.git.DiffType
|
||||
import com.jetpackduba.gitnuro.git.diff.DiffResult
|
||||
|
||||
sealed interface ViewDiffResult {
|
||||
@ -10,5 +10,5 @@ sealed interface ViewDiffResult {
|
||||
|
||||
object DiffNotFound : ViewDiffResult
|
||||
|
||||
data class Loaded(val diffEntryType: DiffEntryType, val diffResult: DiffResult) : ViewDiffResult
|
||||
data class Loaded(val diffType: DiffType, val diffResult: DiffResult) : ViewDiffResult
|
||||
}
|
Loading…
Reference in New Issue
Block a user