diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/StatusViewModel.kt b/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/StatusViewModel.kt index 8425de9..920ce17 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/StatusViewModel.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/StatusViewModel.kt @@ -85,17 +85,18 @@ class StatusViewModel @Inject constructor( _searchFilterUnstaged, ) { state, showSearchStaged, filterStaged, showSearchUnstaged, filterUnstaged -> if (state is StageState.Loaded) { + val unstaged = if (showSearchUnstaged && filterUnstaged.text.isNotBlank()) { state.unstaged.filter { it.filePath.lowercaseContains(filterUnstaged.text) } } else { state.unstaged - } + }.prioritizeConflicts() val staged = if (showSearchStaged && filterStaged.text.isNotBlank()) { state.staged.filter { it.filePath.lowercaseContains(filterStaged.text) } } else { state.staged - } + }.prioritizeConflicts() state.copy(stagedFiltered = staged, unstagedFiltered = unstaged) @@ -108,6 +109,21 @@ class StatusViewModel @Inject constructor( StageState.Loading ) + fun List.prioritizeConflicts(): List { + return this.groupBy { it.filePath } + .map { + val statusEntries = it.value + return@map if (statusEntries.count() == 1) { + statusEntries.first() + } else { + val conflictingEntry = + statusEntries.firstOrNull { entry -> entry.statusType == StatusType.CONFLICTING } + + conflictingEntry ?: statusEntries.first() + } + } + } + var savedCommitMessage = CommitMessage("", MessageType.NORMAL) var hasPreviousCommits = true // When false, disable "amend previous commit" @@ -129,7 +145,8 @@ class StatusViewModel @Inject constructor( private val _isAmend = MutableStateFlow(false) val isAmend: StateFlow = _isAmend - private val _isAmendRebaseInteractive = MutableStateFlow(true) // TODO should copy message from previous commit when this is required + private val _isAmendRebaseInteractive = + MutableStateFlow(true) // TODO should copy message from previous commit when this is required val isAmendRebaseInteractive: StateFlow = _isAmendRebaseInteractive init {