-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix: select next deck after deletion to prevent Default deck appearing in StudyOptionsFragment #21285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix: select next deck after deletion to prevent Default deck appearing in StudyOptionsFragment #21285
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,7 +39,6 @@ import com.ichi2.anki.common.destinations.BrowserDestination | |
| import com.ichi2.anki.configureRenderingMode | ||
| import com.ichi2.anki.launchCatchingIO | ||
| import com.ichi2.anki.libanki.CardId | ||
| import com.ichi2.anki.libanki.Consts | ||
| import com.ichi2.anki.libanki.Consts.DEFAULT_DECK_ID | ||
| import com.ichi2.anki.libanki.DeckId | ||
| import com.ichi2.anki.libanki.Decks | ||
|
|
@@ -208,10 +207,24 @@ class DeckPickerViewModel : | |
| fun deleteDeck(did: DeckId) = | ||
| viewModelScope.launch { | ||
| val deckName = withCol { decks.getLegacy(did)!!.name } | ||
| val changes = undoableOp { decks.remove(listOf(did)) } | ||
| // After deletion: decks.current() reverts to Default, necessitating `focusedDeck` | ||
| // to match and avoid unnecessary scrolls in `renderPage()`. | ||
| focusedDeck = Consts.DEFAULT_DECK_ID | ||
| var nextDeckId = DEFAULT_DECK_ID | ||
| val changes = | ||
| undoableOp { | ||
| val opChanges = decks.remove(listOf(did)) | ||
| // After deletion: decks.current() reverts to Default. Select the first | ||
| // remaining non-Default deck (in deck-list order) so the fragmented study | ||
| // panel shows a sensible deck rather than empty Default. | ||
| // This must happen inside the collection lock so ChangeManager subscribers | ||
| // that read decks.current() see the updated selection. | ||
| nextDeckId = sched | ||
| .deckDueTree() | ||
| .children | ||
| .firstOrNull { it.did != DEFAULT_DECK_ID } | ||
| ?.did ?: DEFAULT_DECK_ID | ||
|
Comment on lines
+219
to
+223
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with lukstbit: define a 'basic' algorithm to select the next node within the tree/list |
||
| decks.select(nextDeckId) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Look into using Then, consider using two |
||
| opChanges | ||
| } | ||
| focusedDeck = nextDeckId | ||
|
|
||
| deckDeletedNotification.emit( | ||
| DeckDeletionResult(deckName = deckName, cardsDeleted = changes.count), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment feels 'Claude':