Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

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

// 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

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

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

opChanges
}
focusedDeck = nextDeckId

deckDeletedNotification.emit(
DeckDeletionResult(deckName = deckName, cardsDeleted = changes.count),
Expand Down
Loading