Skip to content

fix: select next deck after deletion to prevent Default deck appearing in StudyOptionsFragment#21285

Open
sanjaysargam wants to merge 1 commit into
ankidroid:mainfrom
sanjaysargam:delete
Open

fix: select next deck after deletion to prevent Default deck appearing in StudyOptionsFragment#21285
sanjaysargam wants to merge 1 commit into
ankidroid:mainfrom
sanjaysargam:delete

Conversation

@sanjaysargam

@sanjaysargam sanjaysargam commented Jun 21, 2026

Copy link
Copy Markdown
Member

Note

Assisted-by: Claude Opus 4.8

Purpose / Description

On tablets, deleting a deck causes StudyOptionsFragment to display the Default deck, even when other non-Default decks remain.

Fixes

Approach

call sched.deckDueTree() to find the first remaining non-Default deck and decks.select() it, so that when StudyOptionsFragment.opExecuted() subsequently calls withCol { decks.current() }, it reads the correct deck instead of the Default that the backend resets to after removal.

How Has This Been Tested?

Medium Tablet API 35

Checklist

Please, go through these checks before submitting the PR.

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

@sanjaysargam sanjaysargam marked this pull request as ready for review June 21, 2026 05:13

@lukstbit lukstbit left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait for another opinion but I think it would be better if the next selected deck after deleting a deck is one of the deleted deck's siblings or its parent(if it was the only child) so the selection doesn't jump(possible out of screen).

@david-allison david-allison left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition: the ViewModels to be well-tested, as these will continue to be core functionality after our move to Compose

  • Only one opChanges is published
  • A few tests about the next deck: child deck, child deck with sibling before/after; child deck with both siblings; parent deck

Comment on lines +219 to +223
nextDeckId = sched
.deckDueTree()
.children
.firstOrNull { it.did != DEFAULT_DECK_ID }
?.did ?: DEFAULT_DECK_ID

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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

.children
.firstOrNull { it.did != DEFAULT_DECK_ID }
?.did ?: DEFAULT_DECK_ID
decks.select(nextDeckId)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look into using decks.setCurrent() which returns an opChanges - you will want to test ACTIVE_DECKS is set as expected

Then, consider using two withCol calls, collect the opChanges, combine them, publish as one event

val changes =
undoableOp {
val opChanges = decks.remove(listOf(did))
// After deletion: decks.current() reverts to Default. Select the first

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment feels 'Claude':

  • Make it less verbose
  • State that this explicitly deviates from Anki Desktop
  • Mention all of:
    • Unexpected scrolling around the deck list
    • Selecting a 'Default' deck which is not visible in the sidebar (allowing it to be studied)
    • Fragmented View

@david-allison david-allison added the Needs Author Reply Waiting for a reply from the original author label Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Author Reply Waiting for a reply from the original author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deck deletion causes Default deck to appear in right window when DeckPicker is fragmented

3 participants