Skip to content

Commit

Permalink
chore(libanki): parentsByName()
Browse files Browse the repository at this point in the history
  • Loading branch information
BrayanDSO committed May 1, 2024
1 parent e7c8164 commit 78fa72d
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/libanki/Decks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,27 @@ class Decks(private val col: Collection) {
return parents.toList()
}

/** All existing parents of name */
@LibAnkiAlias("parents_by_name")
fun parentsByName(name: String): List<Deck> {
if (!name.contains("::")) {
return listOf()
}
val names = immediateParentPath(name)
val head = mutableListOf<String>()
val parents = mutableListOf<Deck>()

for (deckName in names) {
head.add(deckName)
val deck = byName(head.joinToString("::"))
if (deck != null) {
parents.append(deck)
}
}

return parents.toList()
}

/*
* Filtered decks
*************************************************************
Expand Down

0 comments on commit 78fa72d

Please sign in to comment.