Added diff update when staging/unstagins (files & hunks)
This commit is contained in:
parent
ad55f41f58
commit
6ddb77bf60
@ -28,7 +28,7 @@ import org.eclipse.jgit.diff.DiffEntry
|
|||||||
fun Diff(gitManager: GitManager, diffEntryType: DiffEntryType, onCloseDiffView: () -> Unit) {
|
fun Diff(gitManager: GitManager, diffEntryType: DiffEntryType, onCloseDiffView: () -> Unit) {
|
||||||
var text by remember { mutableStateOf(listOf<Hunk>()) }
|
var text by remember { mutableStateOf(listOf<Hunk>()) }
|
||||||
|
|
||||||
LaunchedEffect(diffEntryType.diffEntry) {
|
LaunchedEffect(Unit) {
|
||||||
text = gitManager.diffFormat(diffEntryType)
|
text = gitManager.diffFormat(diffEntryType)
|
||||||
|
|
||||||
|
|
||||||
|
@ -127,6 +127,7 @@ fun RepositoryOpenPage(gitManager: GitManager) {
|
|||||||
if (selectedItem == SelectedItem.UncommitedChanges) {
|
if (selectedItem == SelectedItem.UncommitedChanges) {
|
||||||
UncommitedChanges(
|
UncommitedChanges(
|
||||||
gitManager = gitManager,
|
gitManager = gitManager,
|
||||||
|
selectedEntryType = diffSelected,
|
||||||
onStagedDiffEntrySelected = { diffEntry ->
|
onStagedDiffEntrySelected = { diffEntry ->
|
||||||
diffSelected = if (diffEntry != null)
|
diffSelected = if (diffEntry != null)
|
||||||
DiffEntryType.StagedDiff(diffEntry)
|
DiffEntryType.StagedDiff(diffEntry)
|
||||||
|
@ -30,6 +30,7 @@ import androidx.compose.ui.unit.sp
|
|||||||
import app.extensions.filePath
|
import app.extensions.filePath
|
||||||
import app.extensions.icon
|
import app.extensions.icon
|
||||||
import app.extensions.iconColor
|
import app.extensions.iconColor
|
||||||
|
import app.git.DiffEntryType
|
||||||
import app.git.GitManager
|
import app.git.GitManager
|
||||||
import app.git.StageStatus
|
import app.git.StageStatus
|
||||||
import app.theme.headerBackground
|
import app.theme.headerBackground
|
||||||
@ -43,6 +44,7 @@ import org.eclipse.jgit.diff.DiffEntry
|
|||||||
@Composable
|
@Composable
|
||||||
fun UncommitedChanges(
|
fun UncommitedChanges(
|
||||||
gitManager: GitManager,
|
gitManager: GitManager,
|
||||||
|
selectedEntryType: DiffEntryType?,
|
||||||
onStagedDiffEntrySelected: (DiffEntry?) -> Unit,
|
onStagedDiffEntrySelected: (DiffEntry?) -> Unit,
|
||||||
onUnstagedDiffEntrySelected: (DiffEntry) -> Unit,
|
onUnstagedDiffEntrySelected: (DiffEntry) -> Unit,
|
||||||
) {
|
) {
|
||||||
@ -55,12 +57,28 @@ fun UncommitedChanges(
|
|||||||
gitManager.loadStatus()
|
gitManager.loadStatus()
|
||||||
}
|
}
|
||||||
|
|
||||||
val (staged, unstaged) = if (stageStatus is StageStatus.Loaded) {
|
val staged: List<DiffEntry>
|
||||||
stageStatus.staged to stageStatus.unstaged
|
val unstaged: List<DiffEntry>
|
||||||
|
if (stageStatus is StageStatus.Loaded) {
|
||||||
|
staged = stageStatus.staged
|
||||||
|
unstaged = stageStatus.unstaged
|
||||||
|
LaunchedEffect(staged) {
|
||||||
|
if(selectedEntryType != null) {
|
||||||
|
checkIfSelectedEntryShouldBeUpdated(
|
||||||
|
selectedEntryType = selectedEntryType,
|
||||||
|
staged = staged,
|
||||||
|
unstaged = unstaged,
|
||||||
|
onStagedDiffEntrySelected = onStagedDiffEntrySelected,
|
||||||
|
onUnstagedDiffEntrySelected = onUnstagedDiffEntrySelected,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
listOf<DiffEntry>() to listOf<DiffEntry>() // return 2 empty lists if still loading
|
staged = listOf<DiffEntry>()
|
||||||
|
unstaged = listOf<DiffEntry>() // return empty lists if still loading
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var commitMessage by remember { mutableStateOf("") }
|
var commitMessage by remember { mutableStateOf("") }
|
||||||
val doCommit = {
|
val doCommit = {
|
||||||
gitManager.commit(commitMessage)
|
gitManager.commit(commitMessage)
|
||||||
@ -170,6 +188,40 @@ fun UncommitedChanges(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun checkIfSelectedEntryShouldBeUpdated(
|
||||||
|
selectedEntryType: DiffEntryType,
|
||||||
|
staged: List<DiffEntry>,
|
||||||
|
unstaged: List<DiffEntry>,
|
||||||
|
onStagedDiffEntrySelected: (DiffEntry?) -> Unit,
|
||||||
|
onUnstagedDiffEntrySelected: (DiffEntry) -> Unit,
|
||||||
|
) {
|
||||||
|
val selectedDiffEntry = selectedEntryType.diffEntry
|
||||||
|
val selectedEntryTypeNewId = selectedDiffEntry.newId.name()
|
||||||
|
|
||||||
|
if (selectedEntryType is DiffEntryType.StagedDiff) {
|
||||||
|
val entryType = staged.firstOrNull { it.newPath == selectedDiffEntry.newPath }
|
||||||
|
|
||||||
|
if(
|
||||||
|
entryType != null &&
|
||||||
|
selectedEntryTypeNewId != entryType.newId.name()
|
||||||
|
) {
|
||||||
|
onStagedDiffEntrySelected(entryType)
|
||||||
|
} else if (entryType == null)
|
||||||
|
onStagedDiffEntrySelected(null)
|
||||||
|
} else if(selectedEntryType is DiffEntryType.UnstagedDiff) {
|
||||||
|
val entryType = unstaged.firstOrNull {
|
||||||
|
if(selectedDiffEntry.changeType == DiffEntry.ChangeType.DELETE)
|
||||||
|
it.oldPath == selectedDiffEntry.oldPath
|
||||||
|
else
|
||||||
|
it.newPath == selectedDiffEntry.newPath
|
||||||
|
}
|
||||||
|
|
||||||
|
if(entryType != null) {
|
||||||
|
onUnstagedDiffEntrySelected(entryType)
|
||||||
|
} else onStagedDiffEntrySelected(null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalAnimationApi::class)
|
@OptIn(ExperimentalAnimationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
private fun EntriesList(
|
private fun EntriesList(
|
||||||
|
Loading…
Reference in New Issue
Block a user