Skip to content

Commit 95e7cbb

Browse files
committed
Fixed commit/merge/rebase button being disabled when filtering all items
1 parent 6086bf2 commit 95e7cbb

File tree

2 files changed

+46
-7
lines changed

2 files changed

+46
-7
lines changed

src/main/kotlin/com/jetpackduba/gitnuro/ui/UncommitedChanges.kt

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ private fun CommitField(
347347
fun ColumnScope.StagedView(
348348
stageStateUi: StageStateUi.Loaded,
349349
showSearchUnstaged: Boolean,
350-
searchFilterUnstaged: TextFieldValue,
350+
searchFilterStaged: TextFieldValue,
351351
stagedListState: LazyListState,
352352
selectedEntryType: DiffType?,
353353
onSearchFilterToggled: (Boolean) -> Unit,
@@ -381,7 +381,7 @@ fun ColumnScope.StagedView(
381381
entryType = EntryType.STAGED,
382382
stageStateUi = stageStateUi,
383383
showSearchUnstaged = showSearchUnstaged,
384-
searchFilterUnstaged = searchFilterUnstaged,
384+
searchFilterUnstaged = searchFilterStaged,
385385
listState = stagedListState,
386386
selectedEntryType = selectedEntryType,
387387
onSearchFilterToggled = onSearchFilterToggled,
@@ -397,8 +397,20 @@ fun ColumnScope.StagedView(
397397
onAlternateShowAsTree = onAlternateShowAsTree,
398398
onTreeDirectoryClicked = onTreeDirectoryClicked,
399399
onTreeDirectoryAction = onTreeDirectoryAction,
400-
onTreeEntries = { it.staged },
401-
onListEntries = { it.staged },
400+
onTreeEntries = {
401+
if (searchFilterStaged.text.trim().isEmpty()) {
402+
it.staged
403+
} else {
404+
it.filteredStaged
405+
}
406+
},
407+
onListEntries = {
408+
if (searchFilterStaged.text.trim().isEmpty()) {
409+
it.staged
410+
} else {
411+
it.filteredStaged
412+
}
413+
},
402414
onGetSelectedEntry = { if (selectedEntryType is DiffType.StagedDiff) selectedEntryType else null },
403415
)
404416
}
@@ -457,8 +469,20 @@ fun ColumnScope.UnstagedView(
457469
onAlternateShowAsTree = onAlternateShowAsTree,
458470
onTreeDirectoryClicked = onTreeDirectoryClicked,
459471
onTreeDirectoryAction = onTreeDirectoryAction,
460-
onTreeEntries = { it.unstaged },
461-
onListEntries = { it.unstaged },
472+
onTreeEntries = {
473+
if (searchFilterUnstaged.text.trim().isEmpty()) {
474+
it.unstaged
475+
} else {
476+
it.filteredUnstaged
477+
}
478+
},
479+
onListEntries = {
480+
if (searchFilterUnstaged.text.trim().isEmpty()) {
481+
it.unstaged
482+
} else {
483+
it.filteredUnstaged
484+
}
485+
},
462486
onGetSelectedEntry = { if (selectedEntryType is DiffType.UnstagedDiff) selectedEntryType else null },
463487
)
464488
}

src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/StatusViewModel.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class StatusViewModel @Inject constructor(
101101
state.staged
102102
}.prioritizeConflicts()
103103

104-
state.copy(staged = staged, unstaged = unstaged)
104+
state.copy(filteredStaged = staged, filteredUnstaged = unstaged)
105105

106106
} else {
107107
state
@@ -128,12 +128,19 @@ class StatusViewModel @Inject constructor(
128128
stageStateFiltered.unstaged,
129129
contractedDirectories
130130
) { it.filePath },
131+
filteredStaged = entriesToTreeEntry(stageStateFiltered.filteredStaged, contractedDirectories) { it.filePath },
132+
filteredUnstaged = entriesToTreeEntry(
133+
stageStateFiltered.filteredUnstaged,
134+
contractedDirectories
135+
) { it.filePath },
131136
isPartiallyReloading = stageStateFiltered.isPartiallyReloading,
132137
)
133138
} else {
134139
StageStateUi.ListLoaded(
135140
staged = stageStateFiltered.staged,
136141
unstaged = stageStateFiltered.unstaged,
142+
filteredStaged = stageStateFiltered.filteredStaged,
143+
filteredUnstaged = stageStateFiltered.filteredUnstaged,
137144
isPartiallyReloading = stageStateFiltered.isPartiallyReloading,
138145
)
139146
}
@@ -310,7 +317,9 @@ class StatusViewModel @Inject constructor(
310317

311318
_stageState.value = StageState.Loaded(
312319
staged = staged,
320+
filteredStaged = staged,
313321
unstaged = unstaged,
322+
filteredUnstaged = unstaged,
314323
isPartiallyReloading = false,
315324
)
316325
}
@@ -610,7 +619,9 @@ sealed interface StageState {
610619
data object Loading : StageState
611620
data class Loaded(
612621
val staged: List<StatusEntry>,
622+
val filteredStaged: List<StatusEntry>,
613623
val unstaged: List<StatusEntry>,
624+
val filteredUnstaged: List<StatusEntry>,
614625
val isPartiallyReloading: Boolean,
615626
) : StageState
616627
}
@@ -637,7 +648,9 @@ sealed interface StageStateUi {
637648

638649
data class TreeLoaded(
639650
val staged: List<TreeItem<StatusEntry>>,
651+
val filteredStaged: List<TreeItem<StatusEntry>>,
640652
val unstaged: List<TreeItem<StatusEntry>>,
653+
val filteredUnstaged: List<TreeItem<StatusEntry>>,
641654
val isPartiallyReloading: Boolean,
642655
) : Loaded {
643656

@@ -651,7 +664,9 @@ sealed interface StageStateUi {
651664

652665
data class ListLoaded(
653666
val staged: List<StatusEntry>,
667+
val filteredStaged: List<StatusEntry>,
654668
val unstaged: List<StatusEntry>,
669+
val filteredUnstaged: List<StatusEntry>,
655670
val isPartiallyReloading: Boolean,
656671
) : Loaded {
657672
override val hasStagedFiles: Boolean = staged.isNotEmpty()

0 commit comments

Comments
 (0)